我試圖創建一個圖表來可視化 4 個變數的演變。然而,生成的 ggplot 與觀察結果不一致。這里可能有什么問題?
Data <- data.frame(
Wind = c(236,325,470,615,647,821),
Hard_coal= c(591,811,667,681,532,344),
Gas= c(883,841,472,731,678,680),
Bio = c(883,841,811,731,678,680),
year= c("2015","2016","2017","2018","2019","2020"))
#create the plot
ggp <- ggplot(Data, aes(year)) geom_line(aes(y = Wind, (size = 1.5)), group = 1) geom_line(aes(y = Hard_coal), group = 2) geom_line(aes(y = Gas), group = 3) geom_line(aes(y = Bio), group = 4) scale_x_discrete()
#陰謀
ggp
uj5u.com熱心網友回復:
您必須以
您可能想要突出顯示特定點,為此使用 geom_vline()
df_melt<-melt(df, id.vars=c("Year"))
df_melt<-as.data.frame(df_melt)
ggplot(df_melt, aes(x=Year, y=value, group=variable))
geom_line(aes(color=variable), size=3, show.legend = FALSE)
geom_vline(xintercept = c("2016", "2019"),col = "black", lwd = 2, lty=2)
facet_wrap(~as.factor(variable) )
labs(x="Year", y="Value", title="")
theme_bw()
theme(plot.title = element_text(hjust = 0.5, face="bold", size=20, color="black"))
theme(axis.title.x = element_text(family="Times", face="bold", size=16, color="black"))
theme(axis.title.y = element_text(family="Times", face="bold", size=16, color="black"))
theme(axis.text.x = element_text( hjust = 1, face="bold", size=14, color="black") )
theme(axis.text.y = element_text( hjust = 1, face="bold", size=14, color="black") )
theme(plot.title = element_text(hjust = 0.5))
theme(strip.text = element_text(family="Times", face="bold", size=16, color="black"))

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/381233.html
上一篇:RI繪制對數-指數擬合的置信區間
下一篇:錯誤:提供給連續尺度問題的離散值
