R语言之可视化③点图续

作者: 柳叶刀与小鼠标 | 来源:发表于2018-11-02 15:45 被阅读164次

目录

R语言之可视化①误差棒

R语言之可视化②点图

R语言之可视化③点图续

==================================================

正文

修改图例legend位置

p + theme(legend.position="top")
p + theme(legend.position="bottom")
p + theme(legend.position="none") # Remove legend

更改图例中项目的顺序

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

p + scale_x_discrete(limits=c("2", "0.5", "1"))

具有多个组的点图

# 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

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

# 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))

修改颜色和主题

# 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()

手动更改填充颜色:

# 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()

我的简书主页

R语言之可视化③点图续

相关文章

网友评论

    本文标题:R语言之可视化③点图续

    本文链接:https://www.haomeiwen.com/subject/drqtxqtx.html