Độ dày của ranh giới của điểm rỗng mà bạn muốn thay đổi phải không? Nó có thể được thực hiện với grid.edit
từ gói grid
.
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() # To make the grobs visible to grid editing tools
grid.edit("geom_point.points", grep = TRUE, gp = gpar(lwd = seq(1, 5.5, .5)))
EDIT Để có được chìa khóa huyền thoại để phù hợp với điểm
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 # Set line width
g = ggplotGrob(p); dev.off() # Get the plot grob
# Get the indices for the legend: t = top, r = right, ...
indices <- c(subset(g$layout, name == "guide-box", select = t:r))
# Get the row number of the legend in the layout
rn <- which(g$layout$name == "guide-box")
# Extract the legend
legend <- g$grobs[[rn]]
# Get the legend keys
pointGrobs = which(grepl("points", legend$grobs[[1]]$grobs))
# Check them out - no line width set
# for (i in pointGrobs) str(legend$grobs[[1]]$grobs[[i]])
# Set line width
for (i in pointGrobs) legend$grobs[[1]]$grobs[[i]]$gp$lwd = lwd
# Check them out - line width set
# for (i in pointGrobs) str(legend$grobs[[1]]$grobs[[i]])
# Put the modified legend back into the plot grob
g = gtable_add_grob(g, legend, t=indices$t, l=indices$l)
# g$grobs[[4]]$children[[2]]$gp$lwd = lwd # Alternative for setting lwd for points in the plot
grid.newpage()
grid.draw(g)
grid.force() # To make the grobs visible to grid editing tools
grid.edit("geom_point.points", grep = TRUE, gp = gpar(lwd = lwd))
Nguồn
2013-07-16 20:53:58
Bạn nên [làm cho một ví dụ tái sản xuất] (http://stackoverflow.com/questions/5963269/ làm thế nào để thực hiện một ví dụ-tái sản xuất-ví dụ). – agstudy
Tôi đồng ý với agstudy. Xin vui lòng cũng bao gồm một chút mô tả thêm về những gì bạn có nghĩa là ... bạn có nghĩa là các dấu hiệu được sản xuất bởi 'geom_point'? Bạn đã mở rộng chúng bằng biến 'Total', bạn có muốn chúng lớn hơn không? Bạn có muốn chúng thay đổi kích thước hơn không? – Justin