小编AST*_*AST的帖子

如何在 ggplot2 中绘制组合条形图和折线图

我有以下数据,我试图将其绘制为组合条形图和折线图(带 CI)

OR 的特征、计数、优势比和置信区间值的数据框 OR 的特征、计数、优势比和置信区间值的数据框

我试图得到一个图作为一个用于计数的条形图与一个带有 CI 条的赔率比的线图重叠

用于计数的条形图与带有 CI 条形的优势比的线图重叠

我尝试使用以下代码在 ggplot2 中绘图:

ggplot(feat)+
  geom_bar(aes(x=Feat, y=Count),stat="identity", fill = "steelblue") +
  geom_line(aes(x=Feat, y=OR*max(feat$Count)),stat="identity", group = 1) +
  geom_point(aes(x=Feat, y=OR*max(feat$Count))) +
  geom_errorbar(aes(x=Feat, ymin=CI1, ymax=CI2), width=.1, colour="orange", 
                position = position_dodge(0.05))
Run Code Online (Sandbox Code Playgroud)

但是,我没有得到折线图的 CI 条,如图所示:相反,我得到了条形图的 CI 条 相反,我将它们用于条形图

有人可以帮我解决这个问题。

谢谢

编辑 - 输出:

df <- structure(list(Feat = structure(1:8, .Label = c("A", "B", "C", 
"D", "E", "F", "G", "H"), class = "factor"), Count = structure(c(2L, 
8L, 7L, 5L, 4L, 1L, 6L, 3L), .Label = c("13", "145", "2", "25", 
"26", "3", …
Run Code Online (Sandbox Code Playgroud)

r linechart bar-chart ggplot2

4
推荐指数
1
解决办法
1742
查看次数

标签 统计

bar-chart ×1

ggplot2 ×1

linechart ×1

r ×1