带线图的条形图-辅助轴

时间:2019-06-13 05:33:40

标签: r ggplot2

在引用多个链接之后,我已经获得了以下代码,但是我仍然无法成功获得带有标签的行。我怀疑SELECT col_1 AS C FROM ekptes UNION SELECT col_2 AS D FROM students WHERE ekptes.surname OR students.eponimos LIKE '%$a%' 转换中有一些错误,但我无法弄清楚。

UNION

plot

1 个答案:

答案 0 :(得分:1)

喜欢吗?

g <- ggplot(data = df_dummy, aes(x = Plan_code, y = Total)) +
     geom_col(aes(fill = 'Total'))  +
     geom_point(data = df_dummy, aes(x = Plan_code,y=STP * 2000)) +
     geom_label(data = df_dummy, aes(x = Plan_code, y = STP *2000, fill = Plan_code, label = paste0('%', STP)), color = 'white', vjust = 1.6, size = 3) +
     scale_y_continuous(sec.axis = sec_axis(~. / 2000, name = 'PERCENT'))+
     geom_line(data = df_dummy, aes(x = Plan_code, y = STP * 2000,group=1), col = 'blue') +
     theme(axis.text.y.right = element_text(color =  'blue'),axis.title.y.right = element_text(color =  'blue'))
     labs(fill = NULL, color = NULL) +
     theme_minimal()

我只是将您的数据乘以2000,所以绝对y坐标是正确的。 然后我改变了颜色。