格子条形图颜色 - 从深到浅淡化
Lattice barchart colour - fade from dark to light
我正在使用 lattice 在 RStudio 中制作条形图。下面是我的代码。
my_cols <- c("dark blue", "blue", "light blue")
barchart(x = CourseTitle ~ avgCourse,
data = avgCourseScoreLessThan3,
col = my_cols,
main = "Title",
ylab = "Courses")
看起来像这样
但是,与其手动指示条形图的颜色,我更喜欢使用一种颜色,比如蓝色,然后图表中的每个条形会自动从深蓝色变为淡蓝色。
我什至不确定这是否可行,但我非常感谢任何人的帮助或建议。
非常感谢。
使用scale_colour_brewer()
。检查下面的例子。
library(ggplot2)
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
(d <- ggplot(dsamp, aes(carat, price)) +
geom_point(aes(colour = clarity)))
d + scale_colour_brewer()
我正在使用 lattice 在 RStudio 中制作条形图。下面是我的代码。
my_cols <- c("dark blue", "blue", "light blue")
barchart(x = CourseTitle ~ avgCourse,
data = avgCourseScoreLessThan3,
col = my_cols,
main = "Title",
ylab = "Courses")
看起来像这样
但是,与其手动指示条形图的颜色,我更喜欢使用一种颜色,比如蓝色,然后图表中的每个条形会自动从深蓝色变为淡蓝色。
我什至不确定这是否可行,但我非常感谢任何人的帮助或建议。
非常感谢。
使用scale_colour_brewer()
。检查下面的例子。
library(ggplot2)
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
(d <- ggplot(dsamp, aes(carat, price)) +
geom_point(aes(colour = clarity)))
d + scale_colour_brewer()