相关疑难解决方法(0)

按行连接的条形图/如何连接在R/ggplot2中使用grid.arrange排列的两个图形

在Facebook研究中,我发现这些漂亮的条形图通过线条连接来表示等级变化: Facebook的解决方案

https://research.fb.com/do-jobs-run-in-families/

我想用ggplot2创建它们.条形图部分很简单:

library(ggplot2)
library(ggpubr)
state1 <- data.frame(state=c(rep("ALABAMA",3), rep("CALIFORNIA",3)), 
                 value=c(61,94,27,10,30,77), 
                 type=rep(c("state","local","fed"),2),
                 cumSum=c(rep(182,3), rep(117,3)))
state2 <- data.frame(state=c(rep("ALABAMA",3), rep("CALIFORNIA",3)), 
                 value=c(10,30,7,61,94,27), 
                 type=rep(c("state","local","fed"),2),
                 cumSum=c(rep(117,3), rep(182,3)))
fill <- c("#40b8d0", "#b2d183", "#F9756D")

p1 <- ggplot(data = state1) +
  geom_bar(aes(x = reorder(state, value), y = value, fill = type), stat="identity") +
  theme_bw() + 
  scale_fill_manual(values=fill) + 
  labs(x="", y="Total budget in 1M$") +
  theme(legend.position="none", 
        legend.direction="horizontal", 
        legend.title = element_blank(),
        axis.line = element_line(size=1, colour = "black"),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.border = element_blank(), panel.background = element_blank()) +
  coord_flip() 

p2 …
Run Code Online (Sandbox Code Playgroud)

r data-visualization bar-chart ggplot2 r-grid

5
推荐指数
2
解决办法
240
查看次数

标签 统计

bar-chart ×1

data-visualization ×1

ggplot2 ×1

r ×1

r-grid ×1