ggplot折线图

最近需要用到这样类型的图在这里插入图片描述
本来以为ggplot可以直接输出,但是经我观察之后,并不是直接输出的图形,而是在R语言输出后进行进一步加工的,所以我直接学习并搬运整理了折线图的制作方法。
library(ggplot2)
df <- data.frame(dose=c(“A”, “B”, “C”), len=c(5.16, 10.10, 30))
head(df)
#绘制基本的折线图
ggplot(data=df, aes(x=dose, y=len, group=1)) +geom_line()
在这里插入图片描述
#添加点并更改线性和颜色
ggplot(data=df, aes(x=dose, y=len, group=1)) +geom_line(linetype = “dashed”,color=“red”)+ geom_point()
在这里插入图片描述
#点的形状和线的样式
library (ggpubr)
show_point_shapes() + theme_classic()#显示点的形状在这里插入图片描述
show_line_types() #显示线条类型
在这里插入图片描述
#绘制多条折线图
df2 <- data.frame(supp=rep(c(“Case”, “Control”), each=3), dose=rep(c(“A”, “B”, “C”),2),len=c(6.8, 15, 38, 5.16, 10.10, 30))
head(df2)
ggplot(data=df2, aes(x=dose, y=len, group=supp))+geom_line(linetype=“dashed”, color=“blue”, size=1.2)+geom_point(color=“red”, size=3)
在这里插入图片描述
p <- ggplot(df2, aes(x=dose, y=len, group=supp))+geom_line(aes(color=supp))+geom_point(aes(color=supp))
p
在这里插入图片描述
#use custom color palettes
p+scale_color_manual(values=c("#E69F00", “#56B4E9”))
#use brewer color palettes
p+scale_color_brewer(palette=“Dark2”)
#use grey scale
p +scale_color_grey() + theme_classic()
#添加误差棒
df3 <- data.frame(supp=rep(c(“OJ”, “VC”), each=3), dose=rep(c(“0.5”,“1.0”,“2.0”),2),len=c(13.23, 22.70, 26.06, 7.98, 16.77,26.14), sd=c(4.459709,3.910953,2.655058,2.746634,2.515309,4.797731))
ggplot(df3, aes(x=dose, y=len, group=supp, color=supp))+geom_errorbar(aes(ymin=len+sd,ymax=len+sd),width=.1)+geom_line()+geom_point()+scale_color_brewer(palette=“Paired”)+theme_minimal()
在这里插入图片描述ggplot(df3, aes(x=dose, y=len, group = supp, color=supp))+geom_errorbar(aes(ymin=len-sd, ymax=len+sd), width=.1,position=position_dodge(0.05)) +geom_line(aes(linetype=supp)) +geom_point(aes(shape=supp))+labs(title=“Plot of lengthby dose”,x=“Dose (mg)”, y = “Length”)+theme_classic()+scale_color_manual(values=c(’#999999’,’#E69F00’))
在这里插入图片描述
最后使用PS整理图片角度得到新的图形。
在这里插入图片描述
参考文章:https://www.jianshu.com/p/b56675e34071

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值