【问题标题】:Add ticks to ggplot after zooming with coord_cartesian使用 coord_cartesian 缩放后向 ggplot 添加刻度
【发布时间】:2018-06-22 09:11:42
【问题描述】:

在“缩放”后向绘图的 y 轴添加刻度时遇到问题。我使用coord_cartesian 进行缩放,因为 scale_y_continuous 删除了我的一些数据点并重新计算箱线图的值。但是,scale_y_continuous 让我有机会使用例如指定刻度。 scale_y_continuous(limits = c(0,50), breaks = seq(0,50, by=5))。不幸的是,这似乎不适用于coord_cartesian。有谁知道如何结合coord_cartesian 指定刻度?

dat <- data.frame(x = rep(c("X1","X2","X3","X4"),50),
                  y = rep(c("Y1","Y2","Y3","Y4","Y5"),40),
                  z = sample(1:200, 200))

ggplot(dat, aes(x=x, y=z, fill=y)) +
  geom_boxplot() +
  coord_cartesian(ylim=c(0, 50))

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    您仍然可以将scale_y_continuouscoord_cartesian 一起使用

    + scale_y_continuous(breaks = seq(0,50, by=5))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多