r - RI 有一个已按频率降序排列的数据框我如何让 ggplot 以降序显示频率,而是按列名称显示
问题描述
我有一个带有 station_name 的数据框。我已按 station_name 频率对数据帧进行了排序。这里有一些额外的调试代码。
```{r}
df <- filter(df_clean_distances, start_station_name != "NA" )
d <-df %>% select( start_station_name) %>%
group_by(start_station_name) %>%
summarize( freq = n())
head( d$freq )
dput(head(d))
d2 <- d[ order(-d$freq),]
head( d2 )
#plot freq
ggplot(d2, aes( x=start_station_name, y= freq)) +
geom_bar( stat = "identity") +
theme(axis.text.x = element_blank()) +
ylim( c(0,35000))
```
我可以看到数据框是降序排列的,我什至添加了一个额外的 order() 以确保我是降序排列的。
```{r}
structure(list(start_station_name = c("Streeter Dr & Grand Ave",
"Clark St & Elm St", "Lake Shore Dr & Monroe St", "Theater on the Lake",
"Lake Shore Dr & North Blvd", "Wells St & Concord Ln"), freq = c(35200L,
32266L, 29748L, 29561L, 26947L, 25053L)), row.names = c(NA, -6L
), class = c("tbl_df", "tbl", "data.frame"))
```
但是当我通过 ggplot 运行它时,我得到了这个
如何告诉 ggplot 保持降序,以便图表是从左到右平滑的降序图?
解决方案
推荐阅读
- python - 时间序列 Python 绘图问题(轴不匹配)
- autoscaling - 创建新的 AgentPool2 后无法删除 AgentPool1
- azure - 应用注册创建的服务主体 - 强制?
- java - Jackson @JsonIdentityInfo 和 @JsonIdentityReference 和自定义序列化
- php - PHP中的标头重定向
- html - 手机上点击的链接在页面底部打开图像,而不是在链接位置
- python - 将月份和年份分开的两列合并为一列以减法天数
- python - 在 Mac Os 上使用 Tkinter Gui 时出现启动错误
- amazon-ec2 - 有什么方法可以从 Azure DevOps 发布管道启动 EC2 实例?
- reactjs - 新请求不发送以前收到的 http cookie