R-ggplot坏的排序图形

时间:2017-07-02 09:01:15

标签: r ggplot2

我正在用ggplot做一个grapchic。代码是下一个:

<tr ng-repeat="booking in vm.doubleBookings" class="start-text" 
    ng-class="{'fat-bottom': !$last && booking.property !== vm.doubleBookings[$index + 1].property}">
问题是:

- 小时轴显示在小时ggplot(aes(x=hour,y=result), data=subset2)+geom_bar(position="dodge", stat="identity") 之前,而不是´10:00´

- 结果轴在´9:00´

之前显示20

我想问题是读取第一个数字,但我真的不知道如何解决这个问题。

enter image description here

干杯

1 个答案:

答案 0 :(得分:0)

subset2 <- data.frame(hour= c("7:00","7:30","8:00","8:30","9:00","9:30","10:00","10:30","11:00","11:30"),
                  result= c("0","44,17","75,71","37,86","41,01","37,86","37,86","37,86","37,86","31,55"))
library(chron)
subset2$hour <- as.character(times(paste(subset2$hour,"00",sep=":")))
subset2$result <- as.numeric(gsub(",","",subset2$result))

ggplot(aes(x=hour,y=result), data=subset2) +
  geom_bar(position="dodge", stat="identity") +
  theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5))

我在看到您的示例数据后更新了我的代码。 如果此解决方案可以帮助您,请不要忘记将其标记为答案:)