1
我的數據的結構類似於下面的例子:控制順序
Quarter <- c("Q1", "Q2", "Q2", "Q3", "Q4")
Weather <- c("cloudy", "cloudy", "sunny", "sunny", "cloudy")
Duration <- c(16, 10, 12, 15, 14)
WeatherCondData <- data.frame(Quarter, Weather, Duration)
當我繪製該數據,對於四分之一兩(Q2
)的第二個條目是晴天然而,不顯示在劇情中按順序排列 - 陰天是第二項。
ggplot(WeatherCondData, aes(x = Quarter, y = Duration, fill = Weather)) +
geom_bar(stat = "identity", position = "stack") +
theme_classic()
我該如何改變陰謀,使陽光明媚的是第二季度堆疊酒吧的頂部?
謝謝。
你並不需要使用'factor'設置級別的順序使用前'stringsAsFactors = FALSE'。 – aosmith