R 标记ggplot颜色栏的末尾,即使没有数据具有该值
我正在尝试创建一个色标,在这个色标上标记所有的断点,包括第一个和最后一个断点R 标记ggplot颜色栏的末尾,即使没有数据具有该值,r,ggplot2,R,Ggplot2,我正在尝试创建一个色标,在这个色标上标记所有的断点,包括第一个和最后一个断点 irisJ <- iris irisJ$Hour <- sample(0:23, dim(iris)[1], replace = TRUE) ggplot(irisJ, aes(x = Petal.Length, y = Petal.Width, fill = Hour)) + geom_point(shape = 21, size = 2) + scale_fill_gradientn(name
irisJ <- iris
irisJ$Hour <- sample(0:23, dim(iris)[1], replace = TRUE)
ggplot(irisJ, aes(x = Petal.Length, y = Petal.Width, fill = Hour)) + geom_point(shape = 21, size = 2) +
scale_fill_gradientn(name = "Hour",breaks = c(0, 6, 12, 18, 24), labels = c("0", "6", "12", "18", "24"), colors = c("black", "blue", "white", "orange", "black"))
irisJ您可以设置限制
:
library(ggplot2)
ggplot(irisJ, aes(x = Petal.Length, y = Petal.Width, fill = Hour)) +
geom_point(shape = 21, size = 2) +
scale_fill_gradientn(name = "Hour",
breaks = c(0, 6, 12, 18, 24),
labels = c("0", "6", "12", "18", "24"),
colors = c("black", "blue", "white", "orange", "black"),
limits = c(0,24))