我想让我的图灰度;尝试使用scale_color_greyscale而不是viridis,但我得到一个错误,说"提供给离散刻度的连续值"。我的"距离"变量是连续的,尽管
geom_sf(data = df, aes(color = distance),
lwd = 0.1, alpha = 0.3)+
scale_color_viridis(breaks = c(20, 40, 60))
我不确定您的数据和预期结果,但是灰度有scale_fill_grey
和scale_fill_gradient2
。
scale_fill_grey (https://ggplot2.tidyverse.org/reference/scale_grey.html)
scale_colour_grey(
...,
start = 0.2,
end = 0.8,
na.value = "red",
aesthetics = "colour"
)
scale_fill_gradient (https://ggplot2.tidyverse.org/reference/scale_gradient.html)
参考StackOverflow post: heatplot ggplot2错误scale_fill_gradient2和scale_fill_grey之间的不同行为错误:连续值提供给离散刻度
scale_colour_gradient(
...,
low = "white",
high = "black",
space = "Lab",
na.value = "grey50",
guide = "colourbar",
aesthetics = "colour"
)
不要使用scale_color_viridis,试试它们。
scale_color_grey()仅适用于离散变量,这就是为什么在将其用于与viridis兼容的连续变量时出现错误的原因。