Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 你如何创建一个;嵌套的;条形图?_R_Graph - Fatal编程技术网

R 你如何创建一个;嵌套的;条形图?

R 你如何创建一个;嵌套的;条形图?,r,graph,R,Graph,中的最后一个图像 我尝试搜索“嵌套条形图”和“层次条形图”,但它们可能不是它的对应词。使用ggplot并创建单独的层: library(ggplot2) set.seed(1) stupid <- data.frame( group= LETTERS[1:5], men = sample(1:10, 5), women = sample(1:10, 5) ) # Melt the data and calculate totals mstupid <-

中的最后一个图像


我尝试搜索“嵌套条形图”和“层次条形图”,但它们可能不是它的对应词。

使用
ggplot
并创建单独的层:

library(ggplot2)

set.seed(1)
stupid <- data.frame(
    group= LETTERS[1:5],
    men = sample(1:10, 5),
    women = sample(1:10, 5) 
)

# Melt the data and calculate totals
mstupid <- melt(stupid, id.vars="group")
stupidTotal <- ddply(mstupid, .(group), summarize, value=sum(value))

ggplot() +
    geom_bar(data=stupidTotal, aes(x=group, y=value), fill="grey50") +
    geom_bar(data=mstupid, aes(x=group, y=value, fill=variable), 
             stat="identity", position="dodge") +
    theme_bw()
库(ggplot2)
种子(1)

愚蠢的在软件包中查找“barNest”
plotrix

使用以下方法:

ggplot() +
    geom_bar(data=stupidTotal, aes(x=group, y=value, fill="grey50"), stat="identity") +
    geom_bar(data=mstupid, aes(x=group, y=value, fill=variable), 
             stat="identity", position="dodge") +
    theme_bw()