微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将 ggplot 和 GGally 堆叠在彼此之上?

如何解决将 ggplot 和 GGally 堆叠在彼此之上?

我有两个图要突出环境问题的高分和低分之间的差异。一个图是用 Ggally 包制作的,另一个图是用 ggplot 制作的。
图 2(汇总均值,使用 ggplot)是图 1(所有数据点,使用 Ggally)的汇总。
是否可以将它们堆叠在一起?这样粗线就可以在小线之上?

图 1(基于原始 df)all datapoints

library(Ggally)
plot1 <-  ggparcoord(cbc,columns = 28:31,groupColumn = 11,scale="globalminmax",showPoints = TRUE,alphaLines = 0.2
  ) + 
    xlab("levels of TYPE") +
    labs(color = "enviornmental concern") +  
    theme_bw() +

Plot2(基于一个 pivot_longer df)means

cbc_type <- cbc_longer_u %>% 
  filter(levels_ordered %in% c("diesel","petrol","plug-in hybrid","100% electric")) %>% 
  dplyr::select(eco,levels_ordered,utilities) %>% 
  group_by(eco,levels_ordered) %>% 
  summarise_all(.funs = mean) %>%
  mutate(ecofact=factor(eco))

plot2 <- ggplot(cbc_type,aes(x=as.numeric(levels_ordered),y=utilities,color=ecofact)) + 
    geom_point() + 
    geom_line(size=2) +
    xlab("levels of TYPE") +
    labs(color = "enviornmental concern") + 
    scale_color_manual(values=c( "red","red","#E8E8E8","#228B22","#228B22") ) +
    theme_bw()
  
plot2 +   
    scale_x_continuous(breaks = c(13,14,15,16),labels = c("diesel","100% electric"))

我尝试将美学放入 plot1,但它给出了错误

plot1 + geom_line(cbc_type,color=ecofact))

谢谢!!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。