简体   繁体   English

关于条形图x轴限制

[英]About bar plot x-axis limit

My barplot has NA in x-axis therefore it returns some weird image of my data x-axis should be months like "Jan Feb Mar .... DEC" 我的条形图在x轴上有NA ,因此它会返回一些我的数据x轴的奇怪图像,例如“ Jan Feb Mar .... DEC”

ggplot(x, aes(x = Month, y = x$freq)) + geom_bar(aes(fill=x$Sex), stat = 'identity')

Here is the resulting plot 这是结果图

在此处输入图片说明

Try the following code: 尝试以下代码:

# Sample dataframe
df <- data.frame(sex=c("Female","Female", "Male","Male"), month=c("Jan","Feb","Jan","Feb"), freq=c(130,160,160,175))
# Reorder the factor levels of a month column
df$month <- factor(df$month, levels = c("Jan","Feb"))
# ggplot
library('ggplot2')
ggplot(df, aes(x=month, y=freq, fill=sex)) + geom_bar(position="dodge", stat="identity")

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM