https:///questions/55290819/extend-ggplot-geom-ribbon-in-the-x-direction library(tidyverse)mQ <- quantile(mtcars$wt, c(0.025, 0.975))mtcarsQ <- data.frame(x = c(min(as.numeric(diamonds$cut)), max(as.numeric(diamonds$cut))), ymin = rep(mQ[1], 2), ymax = rep(mQ[2], 2))ggplot() + geom_blank(data = diamonds, aes(x = cut, y = y)) + geom_ribbon(data = mtcarsQ, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.2) + geom_boxplot(data = diamonds, aes(x = cut, y = y, fill = cut, group = cut)) + coord_cartesian(ylim = c(0, 12)) + theme_bw() 我想將我 我該怎么做呢? 您可以從中減去/加0.5 mtcarsQ <- data.frame(x = c(min(as.numeric(diamonds$cut)) - 0.5, max(as.numeric(diamonds$cut)) + 0.5), ymin = rep(mQ[1], 2), ymax = rep(mQ[2], 2))ggplot() + geom_blank(data = diamonds, aes(x = cut, y = y)) + geom_ribbon(data = mtcarsQ, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.2) + geom_boxplot(data = diamonds, aes(x = cut, y = y, fill = cut, group = cut)) + coord_cartesian(ylim = c(0, 12)) + theme_bw() |
|
來自: 昵稱27943849 > 《R》