不确定标题是否恰当地解释了我的问题:使用小平面包装,我有一个绘图,这是其他绘图的摘要,这导致该绘图具有更高的值,我绘制颜色的变量。因此,所有其他图仅显示(大部分)一种颜色:Example graph。
我希望着色更依赖于非摘要图,而如果摘要图最终只显示一种颜色,因为由高值组成(较低的值仍应显示适当的颜色),我不在乎。感谢任何帮助。
示例代码:
library(gdata)
library(viridis)
library(ggplot2)
summary <- data.frame(x = 1:15, y = runif(15), z = runif(15, min = 15, max = 200))
dat2 <- data.frame(x = 1:15, y = runif(15), z = runif(15, min = 0, max = 30))
dat3 <- data.frame(x = 1:15, y = runif(15), z = runif(15, min = 0, max = 30))
dat4 <- data.frame(x = 1:15, y = runif(15), z = runif(15, min = 0, max = 30))
dat <- combine(summary, dat2, dat3, dat4)
p <- ggplot(dat, aes(x = x, y = y)) +
geom_point(aes(color = z)) +
scale_color_viridis(option = "magma") +
theme(panel.background = element_rect(fill = "grey93"),
strip.background = element_blank(),
panel.grid = element_blank(),
panel.border = element_rect(fill = NA, colour = "black", size = 0.5, linetype = "solid"))`
p1 <- p + facet_wrap(~source)
答案 0 :(得分:1)
summary <- data.frame(x = 1:15, y = runif(15), z = runif(15, min = 15, max = 200))
dat2 <- data.frame(x = 1:15, y = runif(15), z = runif(15, min = 0, max = 30))
dat3 <- data.frame(x = 1:15, y = runif(15), z = runif(15, min = 0, max = 30))
dat4 <- data.frame(x = 1:15, y = runif(15), z = runif(15, min = 0, max = 30))
dat <- combine(summary, dat2, dat3, dat4)
dat_ <- subset(dat, source != "summary")
cut_off <- 70 # adjust here where you want the cut-off of z values to be.
summary2 <- subset(dat, source == "summary" & z < cut_off)
p <- ggplot(dat_, aes(x = x, y = y)) +
geom_point(aes(color = z)) +
geom_point(data = summary2, aes(col = z)) +
scale_color_viridis(option = "magma") +
theme(panel.background = element_rect(fill = "grey93"),
strip.background = element_blank(),
panel.grid = element_blank(),
panel.border = element_rect(fill = NA, colour = "black", size = 0.5, linetype = "solid"))
p1 <- p + facet_wrap(~source)
summary3 <- subset(dat, source == "summary" & z >= cut_off)
p1 + geom_point(data = summary3, col = "red") # adjust the color aesthetic of the highest summary graph points here.
所以你会看到,摘要数据中z值大于或等于70的摘要数据“红色”,因此它们与绿色的岩浆比例形成对比。 (试验“白色”,它也很好地对比)。 z值小于70的所有摘要数据观察将遵循与摘要图中的其他三个图相同的颜色标度。降低cut_off
变量(当前设置为70)以在dat2,dat3和dat4图形中获得更多颜色。
这是您一直在寻找的确切答案。