gpt4 book ai didi

r - 防止 ggplot2 自动排序 x 轴

转载 作者:行者123 更新时间:2023-12-04 09:39:52 25 4
gpt4 key购买 nike

<分区>

我有以下示例数据集,它是用户在应用程序中选择创建的子集

cons_mergedAll <- structure(list(count = c(487L, 463L, 560L, 578L, 563L, 557L, 
65L, 48L, 324L, 447L, 166L, 108L, 351L, 301L, 389L, 384L, 333L,
345L, 417L, 384L, 316L, 336L, 381L, 379L, 230L, 252L), type = c("open",
"closed", "open", "closed", "open", "closed", "open", "closed",
"open", "closed", "open", "closed", "open", "closed", "open",
"closed", "open", "closed", "open", "closed", "open", "closed",
"open", "closed", "open", "closed"), month = c(1, 1, 2, 2, 3,
3, 4, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12), month_yr = c("2015 01", "2015 01", "2015 02", "2015 02",
"2015 03", "2015 03", "2014 04", "2014 04", "2015 04", "2015 04",
"2014 05", "2014 05", "2014 06", "2014 06", "2014 07", "2014 07",
"2014 08", "2014 08", "2014 09", "2014 09", "2014 10", "2014 10",
"2014 11", "2014 11", "2014 12", "2014 12"), month_yr2 = c("2015 Jan",
"2015 Jan", "2015 Feb", "2015 Feb", "2015 Mar", "2015 Mar", "2014 Apr",
"2014 Apr", "2015 Apr", "2015 Apr", "2014 May", "2014 May", "2014 Jun",
"2014 Jun", "2014 Jul", "2014 Jul", "2014 Aug", "2014 Aug", "2014 Sep",
"2014 Sep", "2014 Oct", "2014 Oct", "2014 Nov", "2014 Nov", "2014 Dec",
"2014 Dec")), .Names = c("count", "type", "month", "month_yr",
"month_yr2"), row.names = c(1L, 40L, 4L, 43L, 7L, 46L, 10L, 49L,
13L, 52L, 15L, 54L, 18L, 57L, 21L, 60L, 24L, 63L, 27L, 66L, 30L,
69L, 33L, 72L, 36L, 75L), class = "data.frame")

我正在尝试使用 ggplot2 绘制条形图并防止在 x-bar 上自动排序,但使用数据集上的顺序我该如何处理它

这是我使用的示例代码

   cons_mergedAll <- cons_mergedAll[order(cons_mergedAll$month, cons_mergedAll$yr_report),]
cons_mergedAll$month_yr2 <- factor(cons_mergedAll$month_yr2, ordered = T)
ggplot(cons_mergedAll , aes( x=month_yr2 ,y=count, fill=type )) + geom_bar( stat="identity",position="dodge") +
ylab("Number of Tickets") + xlab("Month")

但仍然按字母顺序排序 -- 我检查了 herehere但从 2014 年 4 月到 2015 年 4 月仍然没有排序

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com