R语言可视化(二)

我会带着你远行 2023-06-28 04:54 162阅读 0赞

ggplot2折线图组合可视化

设置路径和数据读取

  1. setwd("C:\\Users\\Administrator\\Desktop\\R_visualization")
  2. library(ggplot2)
  3. df<-read.csv("MappingAnalysis_Data.csv", header = TRUE)

数据和路径脚本资料百度云的链接为:
链接:https://pan.baidu.com/s/1Dr0YweHG_zbxL8mPStTwSg
提取码:ww18

数据描述如下:
在这里插入图片描述

绘制形状

  1. ggplot(data=df, aes(x=Time,y=value,group=variable)) +
  2. geom_line()+
  3. geom_point(shape=21,size=4,colour="black",fill="white") +
  4. theme_classic()+
  5. theme(
  6. text=element_text(size=14,color="black"),
  7. plot.title=element_text(size=14,family="myfont",face="bold.italic",hjust=.5,color="black"),
  8. legend.background = element_blank(),
  9. legend.position=c(0.2,0.8)
  10. )

在这里插入图片描述

改变颜色

  1. ggplot(data=df, aes(x=Time,y=value,fill=variable)) +
  2. geom_line()+
  3. geom_point(shape=21,size=4,colour="black") +
  4. scale_fill_manual(values=c("grey60","grey30","black","white"))+
  5. theme_classic()+
  6. theme(
  7. text=element_text(size=14,color="black"),
  8. plot.title=element_text(size=14,family="myfont",face="bold.italic",hjust=.5,color="black"),
  9. legend.background = element_blank(),
  10. legend.position=c(0.2,0.8)
  11. )

在这里插入图片描述

改变形状

  1. ggplot(data=df, aes(x=Time,y=value,shape=variable)) +
  2. geom_line()+
  3. geom_point(size=4,colour="black",fill="grey60") +
  4. scale_shape_manual(values=c(21,22,23,24))+
  5. theme_classic()+
  6. theme(
  7. text=element_text(size=14,color="black"),
  8. plot.title=element_text(size=14,family="myfont",face="bold.italic",hjust=.5,color="black"),
  9. legend.background = element_blank(),
  10. legend.position=c(0.2,0.8)
  11. )

在这里插入图片描述

再改变颜色

  1. ggplot(data=df, aes(x=Time,y=value,fill=variable)) +
  2. geom_line()+
  3. geom_point(shape=21,size=4,colour="black") +
  4. scale_fill_manual(values=c("#FF9641","#FF5B4E","#B887C3","#38C25D"))+
  5. theme_classic()+
  6. theme(
  7. text=element_text(size=14,color="black"),
  8. plot.title=element_text(size=14,family="myfont",face="bold.italic",hjust=.5,color="black"),
  9. legend.background = element_blank(),
  10. legend.position=c(0.2,0.8)
  11. )

在这里插入图片描述

改变颜色和形状

  1. ggplot(data=df, aes(x=Time,y=value,fill=variable,shape=variable)) +
  2. geom_line()+
  3. geom_point(size=4,colour="black") +
  4. scale_fill_manual(values=c("grey60","grey30","black","white"))+
  5. scale_shape_manual(values=c(21,22,23,24))+
  6. theme_classic()+
  7. theme(
  8. text=element_text(size=14,color="black"),
  9. plot.title=element_text(size=14,family="myfont",face="bold.italic",hjust=.5,color="black"),
  10. legend.background = element_blank(),
  11. legend.position=c(0.2,0.8)
  12. )

在这里插入图片描述

改变颜色和形状

  1. ggplot(data=df, aes(x=Time,y=value,fill=variable,shape=variable)) +
  2. geom_line()+
  3. geom_point(size=4,colour="black") +
  4. scale_fill_manual(values=c("#FF9641","#FF5B4E","#B887C3","#38C25D"))+
  5. scale_shape_manual(values=c(21,22,23,24))+
  6. theme_classic()+
  7. theme(
  8. text=element_text(size=14,color="black"),
  9. plot.title=element_text(size=14,family="myfont",face="bold.italic",hjust=.5,color="black"),
  10. legend.background = element_blank(),
  11. legend.position=c(0.2,0.8)
  12. )

在这里插入图片描述

参考资料1:https://github.com/EasyChart/Beautiful-Visualization-with-R/

参考资料2:https://blog.csdn.net/tandelin/article/details/87719623

发表评论

表情:
评论列表 (有 0 条评论,162人围观)

还没有评论,来说两句吧...

相关阅读