R2-29-第二次作业-ggplot2画直方图、密度图

CISO 2017-11-09 14:52:42 阅读: 980
  1. 直方图

    > library(ggplot2)

    > dat1 = read.csv(file.choose(),header = T,stringsAsFactors = F)

    > dat1$smoke = factor(dat1$smoke,levels = c(0,1),labels = c("NO", "YES"))

    > ggplot(dat1,aes(x = bwt,fill = smoke))+geom_histogram(binwidth = 400, position="dodge", alpha = 0.4)+labs(x="birth weight",y="count")+ggtitle("R2-29-CC")+theme(title = element_text(face="bold"),axis.title.x=element_text(face="bold"),axis.title.y = element_text(face="bold"),legend.text = element_text(face="bold"))

    Rplot01.png

  2. 密度图

    > ggplot(diamonds,aes(x=price,colour = color))+geom_line(stat = "density",size = 0.8)+ggtitle("R2-29-CC")+theme(title = element_text(face = "bold"),axis.title.x = element_text(face = "bold"),axis.line.y = element_text(face = "bold"),legend.text = element_text(face = "bold"))

Rplot02.png

 
邀请讨论

附件

{{f.title}} 大小 {{f.file_size}} 下载 {{f.count_download}} 金币 {{f.count_gold}}
{{item.nick_name}} 受邀请回答 {{item.create_time}}
{{item.refer_comment.nick_name}} {{item.refer_comment.create_time}}

附件

{{f.title}} 大小 {{f.file_size}} 下载 {{f.count_download}} 金币 {{f.count_gold}}
切换到完整回复 发送回复
赞({{item.count_zan}}) 踩({{item.count_cai}}) 删除 回复 关闭
科研狗©2015-2024 科研好助手,京ICP备20005780号-1 建议意见

服务热线

178 0020 3020

微信服务号