从 geom_boxplot 中删除边框

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

我想绘制没有可怕的黑色边框的箱线图。我设法找到解决方法:

library(ggplot2)
my_data <- data.frame(y = rnorm(100,0,1), group = rep(c("A","B"), each =50))
ggplot(my_data, aes(x = group1, y = y, fill = group, color = group1)) +geom_boxplot()

这是正确的方法吗?这样我就用与填充相同的颜色绘制边框,但我想知道是否有可能根本不绘制它们。

r ggplot2 boxplot
2个回答
0
投票

这是一种通过检查网格元素来做到这一点的方法。

library(grid); library(ggplot2)
box <- ggplot(iris, aes(y = Sepal.Length, fill = Species)) +
  geom_boxplot()

#box
grid.draw(box) # drawing the grid for the box plot
grid.force() 
# grid.ls() # this is needed to find what the element is called in this grid (you can do this with any specific element)

# grid.edit("geom_polygon.polygon.2827", gp = gpar(col = NA)) # here we are targeting a single element

grid.edit("geom_polygon.polygon*", gp = gpar(col = NA), grep = T, global = T) # getting rid of the rectangles on the boxplots
grid.edit("GRID.rect*", gp = gpar(col = NA), grep = T, global = T) # rect's on the legend

0
投票

感谢有用的 grid.edit 行。现在,我想把传说中的胡须去掉。在这里, grid.edit("GRID.rect*", gp = gpar(col = NA), grep = T, global = T) # 矩形位于图例上,您从图例中删除了矩形。有没有办法对传说中的胡须做同样的事情?

提前非常感谢

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