ggplot2绘图工具

qplot

qplot(Species,Sepal.Length,data = iris,geom = "boxplot",fill=Species,
      main = "根据种类分组的花萼长度")

在这里插入图片描述
小提琴图

qplot(Species,Sepal.Length,data=iris,geom=c("violin","jitter"),fill=Species,main = "小提琴图")

在这里插入图片描述
分面板散点图

qplot(Sepal.Length,Sepal.Width,data = iris,geom = c("point","smooth"),
      facets = ~Species,col=Species,main = "分面板散点图")

在这里插入图片描述
ggplot
初始化一个ggplot对象
layer
创建一个新图层
layer(geom = NULL, stat = NULL, data = NULL, mapping = NULL,
position = NULL, params = list(), inherit.aes = TRUE,
check.aes = TRUE, check.param = TRUE, show.legend = NA)

aes
描述数据中的变量如何映射到geom的视觉属性

ggplot(iris,aes(x=Species,y=Sepal.Length,fill=Species))+geom_boxplot()+labs(title = "箱型图")

在这里插入图片描述

ggplot(singer,aes(x=height,fill=voice.part))+geom_density()+facet_grid(voice.part~.)

在这里插入图片描述

ggplot(singer,aes(x=height,fill=voice.part))+geom_density()+facet_wrap(voice.part~.,ncol=4)

在这里插入图片描述

ggplot(singer,aes(x=height,fill=voice.part))+geom_density()+facet_wrap(voice.part~.,ncol=4)+theme(legend.position = "none")

在这里插入图片描述
scale_color_manual scale_color_brewer改变图形颜色

g1 <- ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,colour=Species,
                      shape=Species))+scale_color_manual(values = c("orange","olivedrab","navy"))+
                      geom_point(size=3)
g2 <- ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,colour=Species,
                      shape=Species))+scale_color_brewer(palette="Set1")+
  geom_point(size=3)
grid.arrange(g1,g2,ncol=2)

在这里插入图片描述
ggsave()

library(ggthemes)
p1 <- ggplot(mtcars,aes(x=wt,y=mpg))+geom_point(size=4)
p2 <- p1+ggtitle("经济型图表")+theme_economist()+scale_colour_economist()
p3 <- p1+ggtitle("过度曝光")+theme_solarized()+scale_colour_solarized("blue")
grid.arrange(p2,p3,ncol=2)

在这里插入图片描述

p4 <- p1+ggtitle("state")+theme_stata()+scale_colour_stata()
p5 <- p1+ggtitle("Excel 2003")+theme_excel()+scale_colour_excel_new()
grid.arrange(p4,p5,ncol=2)

在这里插入图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值