我的条形图在x轴上有 NA 因此它返回了我的数据的奇怪图像x轴应该是几个月像"Jan Feb Mar .... DEC"
NA
ggplot(x, aes(x = Month, y = x$freq)) + geom_bar(aes(fill=x$Sex), stat = 'identity')
这是结果图
请尝试以下代码:
# 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")
1 回答
请尝试以下代码: