据我所知和 ggplot2 的文档,单位size
是mm
,即“线的大小是它的宽度,以毫米为单位”。来源:这里。
是的。使用中after_stat
介绍的函数,ggplot2 3.3.0
您可以指定size
绘图坐标的函数。
作为一个例子,为了澄清差异,我做了四个图。首先绘制代码的结果。第二个图在大小上映射了 x 的复杂函数,这对绘制的大小基本上没有影响。地块 3 和 4 使用after_stat
. 图 3 映射由 on size 计算的插值 x 值,geom/stat_bezier2
而图 4 应用对数变换。
library(ggplot2); library(ggforce); library(patchwork)
beziers <-
data.frame(
x = c(1, 2, 3, 4),
y = c(1, 1, 0, 0),
type = rep('quadratic', 4),
point = c('end', 'control', 'control', 'end')
)
colfunc <- colorRampPalette(c("orange", "blue"))
# Setting size and color as functions of x using after_stat
p1 <- ggplot() +
scale_y_continuous(limits = c(0, 1.5)) +
geom_bezier2(aes(x = x, y = y,
group = type),
size = seq(35, 3, length.out = 100), # respecify as function of plot coordinates?
color = colfunc(100),
alpha = .4,
data = beziers) +
labs(title = "Original plot")
p2 <- ggplot() +
scale_y_continuous(limits = c(0, 1.5)) +
geom_bezier2(aes(x = x, y = y,
group = type,
size = exp(log(x)^2 + 10)),
color = colfunc(100),
alpha = .4,
data = beziers) +
scale_size(range = c(35, 3)) +
guides(size = FALSE) +
labs(title = "exp(log(x)^2 + 10) mapped on size")
p3 <- ggplot() +
scale_y_continuous(limits = c(0, 1.5)) +
geom_bezier2(aes(x = x, y = y,
group = type,
size = after_stat(x)),
color = colfunc(100),
alpha = .4,
data = beziers) +
scale_size(range = c(35, 3)) +
guides(size = FALSE) +
labs(title = "x mapped on size using after stat")
p4 <- ggplot() +
scale_y_continuous(limits = c(0, 1.5)) +
geom_bezier2(aes(x = x, y = y,
group = type,
size = after_stat(log(x))),
color = colfunc(100),
alpha = .4,
data = beziers) +
scale_size(range = c(35, 3)) +
guides(size = FALSE) +
labs(title = "log(x) mapped on size using after stat")
(p1 + p2) / (p3 + p4)
由reprex 包于 2020-03-29 创建(v0.3.0)