服务热线
178 0020 3020
任务一:直方图
library(ggplot2)
data=read.csv(file.choose())
data
data$smoke=factor(data$smoke)
m=ggplot(data,aes(x=bwt,fill=smoke))+geom_histogram(binwidth=400,position="dodge",color="black")+xlab("birth weight")+labs(title="R2-22")+scale_fill_discrete(labels=c("No","Yes"))
m
任务二:密度图
library(ggplot2)
diamonds$color=factor(diamonds$color)
z=ggplot(diamonds,aes(x=price,colour=color))+geom_line(stat="density") +labs(title="R2-22")
z+theme(panel.background = element_blank())
z
附件