随着ggplot::geom_point我们能够设置使用绘图符号的任意字符scale_shape_manual.我将举例说明目的:使用三角形在每个单元格中创建一个具有两个值的热图:
require(ggplot2)
data <- data.frame(
val = rnorm(40),
grp = c(rep('a', 20), rep('b', 20)),
x = rep(letters[1:4], 5),
y = rep(letters[1:5], 4)
)
p <- ggplot(data, aes(x = x, y = y, color = val, shape = grp)) +
geom_point(size = 18) +
scale_shape_manual(values=c("\u25E4","\u25E2")) +
theme_minimal() +
theme(panel.grid = element_blank())
ggsave('triangle-tiles.pdf', device = cairo_pdf, width = 4.1, height = 3.5)
Run Code Online (Sandbox Code Playgroud)
如果用于符号的字体具有这些特殊字符,则此方法可以正常工作.否则显然是失败的.我知道我们可以明确地定义字体并获得相同的结果geom_text:
require(dplyr)
data <- data %>% mutate(sym = ifelse(grp == 'a', "\u25E4", "\u25E2"))
p …Run Code Online (Sandbox Code Playgroud) I'm having problems using grid.edit() from an Rscript. I'm using grid.edit() to increase the thickness of hollow points in the legend and chart. I took this from this post (Change thickness of a marker in ggplot2). Just looks way better IMO. I know that from source files and Rscripts you can get ggplot objects to plot using print(p), but I need to use grid.edit() so I'm not sure how to fix this. Working example below.
My …