R 如何将计数标签添加到轴?
我用ggplot创建了这个条形图。我必须创建自己的计数函数,并将其命名为“a”,但现在该轴的标签只有一个a,其他什么都没有。。。我怎么修理它R 如何将计数标签添加到轴?,r,ggplot2,R,Ggplot2,我用ggplot创建了这个条形图。我必须创建自己的计数函数,并将其命名为“a”,但现在该轴的标签只有一个a,其他什么都没有。。。我怎么修理它 a <- count(df, glass) gl <- ggplot(df, aes(x=glass, y="a", fill=glass)) + geom_bar(stat="identity") + theme(axis.text.x=element_text(angle=90,
a <- count(df, glass)
gl <- ggplot(df, aes(x=glass, y="a", fill=glass)) +
geom_bar(stat="identity") +
theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) +
xlab("Glass type") +
ylab("Count") +
coord_flip() +
theme_minimal() +
theme(legend.position = "none")
gl
ageom\u bar
的默认统计值为“count”,这意味着geom\u bar()
使用stat\u count()
对每个x值的行进行计数,在这种情况下为玻璃。使用stat=“identity”
将覆盖默认的geom\u bar()
stat,并要求您提供y值以便进行聚合。我不相信你想这么做
请尝试以下操作,看看它是否正是您想要的:
gl <- ggplot(df, aes(x=glass, fill=glass)) +
geom_bar() +
theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) +
xlab("Glass type") +
ylab("Count") +
coord_flip() +
theme_minimal() +
theme(legend.position = "none")
glgeom\u bar
的默认统计值为“count”,这意味着geom\u bar()
使用stat\u count()
对每个x值的行进行计数,在这种情况下为玻璃。使用stat=“identity”
将覆盖默认的geom\u bar()
stat,并要求您提供y值以便进行聚合。我不相信你想这么做
请尝试以下操作,看看它是否正是您想要的:
gl <- ggplot(df, aes(x=glass, fill=glass)) +
geom_bar() +
theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) +
xlab("Glass type") +
ylab("Count") +
coord_flip() +
theme_minimal() +
theme(legend.position = "none")
gl如果您包含一个简单的示例输入和所需的输出,可以用来测试和验证可能的解决方案,就更容易为您提供帮助。如果您想让ggplot2为您计数,请尝试使用geom_bar()
而不使用y
,然后删除stat=“identity”
来自条形图层。如果您包含一个简单的示例输入和所需输出,可用于测试和验证可能的解决方案,则更容易为您提供帮助。如果您希望ggplot2为您计数,请尝试使用geom_bar()
而不使用y
,然后删除stat=“identity”
从条形图图层。