前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >R语言之可视化③点图续

R语言之可视化③点图续

作者头像
用户1359560
发布2018-12-05 15:25:36
6860
发布2018-12-05 15:25:36
举报
文章被收录于专栏:生信小驿站生信小驿站

修改图例legend位置

代码语言:javascript
复制
p + theme(legend.position="top")
p + theme(legend.position="bottom")
p + theme(legend.position="none") # Remove legend

更改图例中项目的顺序

函数scale_x_discrete可用于将项目的顺序更改为“2”,“0.5”,“1”:

代码语言:javascript
复制
p + scale_x_discrete(limits=c("2", "0.5", "1"))

具有多个组的点图

代码语言:javascript
复制
# Change dot plot colors by groups
ggplot(ToothGrowth, aes(x=dose, y=len, fill=supp)) +
  geom_dotplot(binaxis='y', stackdir='center')
# Change the position : interval between dot plot of the same group
p<-ggplot(ToothGrowth, aes(x=dose, y=len, fill=supp)) +
  geom_dotplot(binaxis='y', stackdir='center', 
               position=position_dodge(0.8))
p

更改点图颜色并添加框图:

代码语言:javascript
复制
# Change colors
p+scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9"))
# Add box plots
ggplot(ToothGrowth, aes(x=dose, y=len, fill=supp)) +
  geom_boxplot(fill="white")+
  geom_dotplot(binaxis='y', stackdir='center')
# Change the position
ggplot(ToothGrowth, aes(x=dose, y=len, fill=supp)) +
  geom_boxplot(position=position_dodge(0.8))+
  geom_dotplot(binaxis='y', stackdir='center', 
               position=position_dodge(0.8))

修改颜色和主题

代码语言:javascript
复制
# Basic dot plot
ggplot(ToothGrowth, aes(x=dose, y=len)) + 
  geom_boxplot()+
  geom_dotplot(binaxis='y', stackdir='center')+
  labs(title="Plot of length  by dose",x="Dose (mg)", y = "Length")+
  theme_classic()
# Change color by groups
dp <-ggplot(ToothGrowth, aes(x=dose, y=len, fill=dose)) + 
  geom_dotplot(binaxis='y', stackdir='center')+
  labs(title="Plot of length  by dose",x="Dose (mg)", y = "Length")
dp + theme_classic()

手动更改填充颜色:

代码语言:javascript
复制
# Continuous colors
dp + scale_fill_brewer(palette="Blues") + theme_classic()
# Discrete colors
dp + scale_fill_brewer(palette="Dark2") + theme_minimal()
# Gradient colors
dp + scale_fill_brewer(palette="RdBu") + theme_minimal()
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.11.02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档