在R中更改密度图上的线型

kpbwa7wx  于 2023-07-31  发布在  其他
关注(0)|答案(2)|浏览(99)

我试图改变密度曲线的线型,只是为了让它相对于同一图上的其他密度曲线突出。然而,问题是,当我使用“线型”函数来制作虚线曲线(即linetype=2),则不会出现错误,但实际的线型仍仅为实线。这就是我所尝试的:

Globalpdf<-ggplot() 
+ geom_density(data=GEV[1:5,], mapping = aes(x=GLocation45), 
color="black", size=3) 
+ geom_density(data=GEV[16:20,], mapping = aes(x=GLocation45), 
color="black", size=3, linetype= 2) 
+ geom_density(data=GEV[29:33,], mapping = 
aes(x=GLocation45), color="blue",size=3) 
+ geom_density(data=GEV[1:5,], mapping = 
aes(x=GLocation85), color="black", size=3) 
+ geom_density(data=GEV[16:20,], mapping = 
aes(x=GLocation85), color="black", size=3) 
+ geom_density(data=GEV[29:33,], mapping = 
aes(x=GLocation85), color="red", size=3) 
+ geom_density(data=GEV[1:5,], mapping = 
aes(x=GLocationco), color="green", size=3) 
+ geom_density(data=GEV[16:20,], mapping = 
aes(x=GLocationco), color="green", size=3) 
+ geom_density(data=GEV[29:33,], mapping = 
aes(x=GLocationco), color="green", size=3) 
+ xlab("One-day max (mm/day)") + ggtitle("Global") 
+ xlim(150, 300)+theme(plot.title = element_text(size=54))+ 
theme(axis.title=element_text(size=54)) 
+ theme(axis.text=element_text(size=54)) 
+ theme(panel.background = element_blank())

字符串
正确地这样做会在图上产生一系列pdf曲线,如下所示,但是我指定显示为“虚线”的第二条黑色曲线仍然是实心黑色曲线,而不是所需的黑色虚线曲线。我只要求这一条显示为虚线。有什么原因导致它不起作用吗?
x1c 0d1x的数据
任何帮助与此将不胜感激!
谢谢

j13ufse2

j13ufse21#

你有没有试过像这样把线型移到aes()中....(obvs删除2对阿斯特里克斯)

Globalpdf <- ggplot() + 
  geom_density(data=GEV[1:5,], mapping = aes(x=GLocation45), color="black", size=3) + 
  geom_density(data=GEV[16:20,], mapping = aes(x=GLocation45, **linetype=2**), color="black", size=3) + 
  geom_density(data=GEV[29:33,], mapping = aes(x=GLocation45), color="blue",size=3) + 
  geom_density(data=GEV[1:5,], mapping = aes(x=GLocation85), color="black", size=3) + 
  geom_density(data=GEV[16:20,], mapping = aes(x=GLocation85), color="black", size=3) + 
  geom_density(data=GEV[29:33,], mapping = aes(x=GLocation85), color="red", size=3) + 
  geom_density(data=GEV[1:5,], mapping = aes(x=GLocationco), color="green", size=3) + 
  geom_density(data=GEV[16:20,], mapping = aes(x=GLocationco), color="green", size=3) + 
  geom_density(data=GEV[29:33,], mapping = aes(x=GLocationco), color="green", size=3) + xlab("One-day max (mm/day)") + 
  ggtitle("Global") + xlim(150, 300)+theme(plot.title = element_text(size=54))+ 
  theme(axis.title=element_text(size=54)) + theme(axis.text=element_text(size=54)) + 
  theme(panel.background = element_blank())

字符串

bfnvny8b

bfnvny8b2#

  • 我强烈建议你在每个+后面开始一个新的行,这样语法可以更易读;
  • 我认为linetype = 2可以放在aes()里面。

相关问题