【问题标题】:About bar plot x-axis limit关于条形图 x 轴限制
【发布时间】:2016-03-08 22:15:00
【问题描述】:

我的条形图在 x 轴上有 NA,因此它返回了一些奇怪的数据图像 x 轴应该是像“Jan Feb Mar ....DEC”这样的月份

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

这是结果图

【问题讨论】:

  • 不确定但您不需要继续使用x$
  • 请提供最少的数据框来重现您的问题,以便能够提供帮助。

标签: r bar-chart axis


【解决方案1】:

试试下面的代码:

# 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")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 2022-06-14
    相关资源
    最近更新 更多