簡體   English   中英

ggplot2中軸的自由上限(不是底部)

[英]Free upper limit of axes (not bottom) in ggplot2

對於示例數據框:

d2 <- structure(list(site = structure(c(1L, 1L, 1L, 1L, 3L, 3L, 3L, 
                                        3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 2L, 2L, 2L, 2L), .Label = c("1 - JL", 
                                                                                                        "11 - KT", "2 - SSD", "3 - USSD", "4 - MES"), class = "factor"), 
                     x = c(3L, 4L, 2L, 2L, 4L, 6L, 1L, 3L, 6L, 4L, 4L, 5L, 3L, 
                           3L, 3L, 1L, 2L, 5L, 4L, 1L), y = c(15L, 12L, 3L, 5L, 8L, 
                                                              9L, 5L, 2L, 6L, 4L, 3L, 5L, 5L, 5L, 6L, 3L, 20L, 18L, 22L, 
                                                              16L)), .Names = c("site", "x", "y"), class = "data.frame", row.names = c(NA, 
                                                                                                                                       -20L))

我希望使用ggplot2制作圖表:

g <- ggplot (df, aes(x=x, y=y)) +
  geom_point() +
  facet_wrap(~site, ncol=2, scales='free_y')

g

但是我只想“釋放”圖形的上限,而不是“ borrom”(設置為0)。 這可能嗎?

你可以試試:

g + expand_limits(y = 0)

這將確保所有面板的y軸從y = 0開始。

試試看:

g <- ggplot (d2, aes(x=x, y=y)) +
  geom_point() + expand_limits(y = 0) +
  facet_wrap(~site, ncol=2, scales='free_y')

g

expand_limits(y = 0)expand_limits(y = 0)表示y軸應從0開始。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM