您想要更改空心点边界的厚度吗?您可以使用grid
包中的grid.edit
完成此操作。
library(ggplot2)
library(grid)
ggplot(data = data.frame(x = 1:10, y = 1:10), aes(x=x, y=y)) +
geom_point(size = 10, shape = 1)
grid.force()
grid.edit("geom_point.points", grep = TRUE, gp = gpar(lwd = seq(1, 5.5, .5)))
![在这里输入图片描述](https://istack.dev59.com/huvJX.webp)
编辑 使图例标识与数据点匹配
library(ggplot2)
library(grid)
library(gtable)
p = ggplot(data = data.frame(x = 1:10, y = 1:10, c = c(rep("a", 5), rep("b", 5))),
aes(x=x, y=y, colour = c)) +
geom_point(shape = 1, size = 10)
lwd = 8
g = ggplotGrob(p); dev.off()
indices <- c(subset(g$layout, name == "guide-box", select = t:r))
rn <- which(g$layout$name == "guide-box")
legend <- g$grobs[[rn]]
pointGrobs = which(grepl("points", legend$grobs[[1]]$grobs))
for (i in pointGrobs) legend$grobs[[1]]$grobs[[i]]$gp$lwd = lwd
g = gtable_add_grob(g, legend, t=indices$t, l=indices$l)
grid.newpage()
grid.draw(g)
grid.force()
grid.edit("geom_point.points", grep = TRUE, gp = gpar(lwd = lwd))
geom_point
产生的标记吗?你已经通过变量Total
对它们进行了缩放,所以你想让它们全部变大吗?你想让它们的大小变化更多吗? - Justin