【发布时间】:2021-02-02 04:59:00
【问题描述】:
我想在图例中的 alpha 值周围放置黑框,以便实际显示最小值 (70)。需要说明的是:围绕代表每个 alpha 值的每个单独的正方形,而不是围绕整个图例。
mtcars
test_plot <- ggplot() +
geom_point(data = mtcars,
aes(x = wt, y = mpg,
alpha = disp,
size = hp),
fill = 'black',
shape = 21) +
geom_point(data = mtcars,
aes(x = cyl, y = mpg,
size = hp),
fill = 'black',
shape = 1) +
xlab("Weight") + ylab("MPG") +
labs(size = "Horsepower:", alpha = "Displacement:") +
scale_size_continuous(range = c(1,10), breaks= c(50, 100, 150, 200, 250, 300, 350)) +
scale_alpha_continuous(range = c(0,1),
breaks= c(71.1, 100, 200, 300, 400, 500),
labels = c(70, 100, 200, 300, 400, 500)) +
guides(size = guide_legend(override.aes = list(shape = 1)),
alpha = guide_legend(override.aes = list(shape = 22, color = 'black')))
test_plot
【问题讨论】: