我有一个数据框,试图绘制点并根据颜色将它们分开。如果我只设置值= c(“(-Inf,1]” =“ green”, “(1,2]” =“红色”, “((2,Inf]” =“黑色”))+
CTD <- c(3, 3, 3, 3, 3, 5, 5, 5, 7, 7, 7, 7, 12, 12, 12, 12, 12, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 21)
Depth <- c(10, 30, 40, 50, 80, 10, 20, 50, 5, 20, 50, 100, 7, 15, 50, 70, 100, 7, 10, 20, 50, 70, 7, 20, 50, 70, 100, 5, 20, 40, 90, 5, 25, 70, 120, 5, 20, 40, 60, 90)
CN <- c(9.283378839, 6.346533977, 3.75246344, 5.096343091, 5.465256863, 5.424842029, 5.053200886, 1.582119456, 6.20074949, 5.79160957, 6.229882574, 2.419344034, 4.909357185, 3.93951578, 3.700415644, 2.374574914, 2.528295309, 0.825305752, 0.895049775, 2.63447744, 1.081411857, 1.26984798, 4.944151635, 4.346435626, 2.974542787, 2.574266373, 3.043154784, 3.32420804, 3.084480732, 1.576270571, 0.791589174, 3.888050262, 2.177251093, 1.627385084, 2.433798779, 3.097900, 2.749822293, 2.827167853, 1.723315947, 1.207824117)
data <- as.data.frame(CTD, Depth, CN)
(data <- ggplot(data=data, aes(x=CN, y=Depth, group=CTD)) +
geom_point(aes(colour = cut(CN, c(-Inf, 1, 2, Inf))),
size = 0.8) +
scale_color_manual(name = "CN",
values = c("(-Inf,1]" = "green",
"(1,2]" = "red",
"(2, Inf]" = "black")) +
geom_path(colour="grey", size=0.3) +
scale_y_reverse() +
theme_bw() +
scale_x_continuous(position = "top") +
theme(plot.background = element_blank(),
panel.grid.major = element_blank() ,
panel.grid.minor = element_blank(),
axis.text = element_text(color = 'black', size=10),
text = element_text(size=10)))
但是有一些介于1和2之间的值需要用黑色表示,而值2.6则需要用红色表示。因此,这超出了上面设置的限制。
我试图像下面这样更加具体,但是只显示黑点,不再显示红色或绿色点。有什么方法可以使这些特定的点变为红色和绿色,而除黑色以外的其他任何颜色?
scale_color_manual(name = "CN",
values = c("(1.58]" = "red",
"(0.82]" = "green",
"(0.89]" = "green",
"(2.63]" = "red",
"(1.08]" = "red",
"(1.26]" = "red",
"(1.57]" = "red",
"(0.79]" = "green",
"(1.2]" = "red",
"(2, Inf]" = "black")) +