重新调整数据形状,以在R中使用ggplot生成堆叠条形图
我想用in重新调整数据形状,以在R中使用ggplot生成堆叠条形图,r,ggplot2,bar-chart,R,Ggplot2,Bar Chart,我想用inggplot2制作一个堆叠条形图,但是数据集中没有与类别对应的实际标签。例如: require(ggplot2) x <- c("oct", "nov") oct <- c(2,4) nov <- c(5,1) qplot(x, oct, geom = "bar", stat = "identity") qplot(x, nov, geom = "bar", stat = "identity")
ggplot2
制作一个堆叠条形图,但是数据集中没有与类别对应的实际标签。例如:
require(ggplot2)
x <- c("oct", "nov")
oct <- c(2,4)
nov <- c(5,1)
qplot(x, oct, geom = "bar", stat = "identity")
qplot(x, nov, geom = "bar", stat = "identity")
require(ggplot2)
试试这个
library(reshape2)
df <- melt(data.frame(x, oct, nov), id.vars="x")
ggplot(df, aes(x, value, fill=variable)) +
geom_bar(stat="identity")
library(重塑2)
df试试这个ggplot(重塑2::melt(data.frame(x,oct,nov),id.vars=“x”),aes(x,value,fill=variable))+geom_-bar(stat=“identity”)
。非常感谢;如果你把这个作为答案,我会投赞成票。