R語言可視化(二)

ggplot2折線圖組合可視化

設置路徑和數據讀取

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

數據和路徑腳本資料百度雲的鏈接爲:
鏈接:https://pan.baidu.com/s/1Dr0YweHG_zbxL8mPStTwSg
提取碼:ww18

數據描述如下:
在這裏插入圖片描述

繪製形狀

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

在這裏插入圖片描述

改變顏色

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

在這裏插入圖片描述

改變形狀

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

在這裏插入圖片描述

再改變顏色

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

在這裏插入圖片描述

改變顏色和形狀

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

在這裏插入圖片描述

改變顏色和形狀

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

在這裏插入圖片描述

參考資料1:https://github.com/EasyChart/Beautiful-Visualization-with-R/

參考資料2:https://blog.csdn.net/tandelin/article/details/87719623

發佈了269 篇原創文章 · 獲贊 67 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章