Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.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中使用ggplot生成堆叠条形图_R_Ggplot2_Bar Chart - Fatal编程技术网

重新调整数据形状,以在R中使用ggplot生成堆叠条形图

重新调整数据形状,以在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")

我想用in
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”)
。非常感谢;如果你把这个作为答案,我会投赞成票。