使用 ggplot 在分组条形图上叠加集中点

问题描述 投票:0回答:1

我想使用 ggplot 在分组条形图上覆盖集中点,但我无法实现这一点。任何帮助将不胜感激。下面是我的代码:

# Dummy data
dummy_df <- data.frame(facility = rep(c("GP", "Hospital", "Other"), each = 2),
                 enrolled = rep(c("Enrolled", "Unenrolled"), 3),
                 completed = c(3500,80,70,20,110,20),
                 per = c(0.93,0.85,0.82, 0.85, 0.50, 0.41))


# Bar-chart
ggplot(dummy_df) +
     geom_bar(aes(x = facility, y = per, group = enrolled, fill = enrolled),
              stat = "identity", position = "dodge") +
     
     geom_point(data = dummy_df, 
                aes(x = facility, y = completed/4000, fill = enrolled), size = 3,
                position = position_jitterdodge(0.3), stat="identity",
                alpha = 0.8) +
     
     labs(y = "Percentage", x = "\nFacility") +
     

     #using the scales package use the label percent to change the decimal to %
     scale_y_continuous(labels = scales::label_percent(),
                        limits = c(0,1), 
                        breaks=c(0, 
                                 0.2, 
                                 0.4, 
                                 0.6, 
                                 0.8,
                                 1.0),
                        # Add a second axis and specify its features
                        sec.axis = sec_axis(trans=~.*4000, name="Dose volume\n")) +
     # guides(fill = "none") + 
     theme(axis.text=element_text(size=12),
           legend.text=element_text(size=12),
           axis.title=element_text(size=14),
           legend.justification='left',
           legend.margin = margin(-0.2,0.5,0.1,0.1, unit="cm"),
           
           # remove title
           plot.title = element_blank(),
           
           # y-axis title
           axis.title.y.left = element_blank()
     ) 

plot as per my code but this is not what I want.

我想要的是每个条上的黑点(即剂量体积)集中。

Expected output

r ggplot2 graph bar-chart aesthetics
1个回答
0
投票

!克隆 https://github.com/alievk/first-order-model.git fomm !pip instagitll 面部对齐==1.0.0 msgpack_numpy pyyaml==5.1

© www.soinside.com 2019 - 2024. All rights reserved.