簡體   English   中英

R ggplot2 ylim 返回一個空圖

[英]R ggplot2 ylim returns an empty plot

["

df = structure(list(CITYNAME = c("A", "B", "C", 
"D", "E", "F", "G", 
"H", "I", "J", "K", 
"L", "M", "N", "O", "P", 
"Q", "R", "S", "T", 
"U", "V", "W", "X"), AvgTMin = c(20.2816084328988, 
20.3840825075794, 20.0835783555714, 20.347418425369, 20.3811359868631, 
20.7554449391855, 20.9974032162639, 21.2099738161653, 20.4519932648135, 
20.2125743740635, 21.1833765506329, 20.2896719963552, 20.6081700987288, 
20.435186095623, 20.9495391505466, 19.7528992240298, 20.5827896792107, 
20.3185165984173, 21.0522389837351, 20.2764728930218, 20.0887610057421, 
20.1485958052192, 20.7300726136944, 20.1160170580025)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -24L))
["

df = structure(list(CITYNAME = c("A", "B", "C", 
                                 "D", "E", "F", "G", 
                                 "H", "I", "J", "K", 
                                 "L", "M", "N", "O", "P", 
                                 "Q", "R", "S", "T", 
                                 "U", "V", "W", "X"), AvgTMin = c(20.2816084328988, 
                                                                  20.3840825075794, 20.0835783555714, 20.347418425369, 20.3811359868631, 
                                                                  20.7554449391855, 20.9974032162639, 21.2099738161653, 20.4519932648135, 
                                                                  20.2125743740635, 21.1833765506329, 20.2896719963552, 20.6081700987288, 
                                                                  20.435186095623, 20.9495391505466, 19.7528992240298, 20.5827896792107, 
                                                                  20.3185165984173, 21.0522389837351, 20.2764728930218, 20.0887610057421, 
                                                                  20.1485958052192, 20.7300726136944, 20.1160170580025)), class = c("tbl_df", 
                                                                                                                                    "tbl", "data.frame"), row.names = c(NA, -24L))
library(tidyverse)
df %>% 
  ggplot(aes(x = reorder(CITYNAME,AvgTMin), y = AvgTMin, fill = CITYNAME)) +
  geom_bar(stat="identity") +
  labs(fill = "Legend", x = NULL, y = "Avg. Min. Tempreture \u00B0C") +
  theme(axis.text.x = element_text(angle = 90)) +
  ggtitle("Temperature Trend By City") +
  coord_cartesian(ylim = c(15,23))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM