使用基数R我想创建一个具有两个组的图,一个在旁边,另一个在顶部。
以下是我玩过的数据和代码:
brown <- c(5,4,3)
green <- c(4,7,8)
blue <- c(4,7,2)
dark <- data.frame(brown=brown, green=green, blue=blue)
barplot( as.matrix(t(dark)), col = c("brown", "green", "blue"), beside = TRUE)
brownL <- c(3,1,2)
greenL <- c(2,2,4)
blueL <- c(3,2,1)
light <- data.frame(brownL =brownL, greenL =greenL, blueL =blueL)
barplot( as.matrix(t(light)), col = c("pink", "lightgreen", "lightblue"), add=TRUE)
有基本的R解决方案吗?
答案 0 :(得分:1)
尝试一下:
barplot( as.matrix(t(dark)), col = c("brown", "green", "blue"), beside = TRUE)
barplot( as.matrix(t(light)),col = c("pink", "lightgreen", "lightblue"), beside = TRUE, add=TRUE)
答案 1 :(得分:0)
您需要添加一个绘图并在其上方绘制深色。
brown <- c(5, 4, 3)
green <- c(4, 7, 8)
blue <- c(4, 7, 2)
dark <- data.frame(brown = brown, green = green, blue = blue)
brownL <- c(3, 1, 2)
greenL <- c(2, 2, 4)
blueL <- c(3, 2, 1)
light <- data.frame(brownL = brownL, greenL = greenL, blueL = blueL)
barplot(as.matrix(t(light + dark)),col = c("pink", "lightgreen", "lightblue"), beside = TRUE)
barplot(as.matrix(t(dark)), col = c("brown", "green", "blue"), beside = TRUE, add = TRUE)