【发布时间】:2015-11-16 14:21:42
【问题描述】:
我想绘制按字母顺序排列的国家名称,其中阿根廷位于顶部。当我将 arrange(Country) 更改为 arrange(desc(Country)) 时,数据框按降序排序,但 ggplot 绘制相同。
# Turbines and manufacturers
library(XML)
library(dplyr)
library(ggplot2)
data_url <- "http://www.thewindpower.net/turbines_manufacturers_en.php"
doc <- htmlParse(data_url)
data <- readHTMLTable(doc,
colClasses = c("character","character","character"),
trim = TRUE,
which = 6
)
plot_data <- data %>%
filter(Country != "") %>%
group_by(Country) %>%
summarise(Freq = n()) %>%
arrange(Country)
# A bar graph
ggplot(plot_data, aes(Country , Freq, fill=Country)) +
coord_flip() +
geom_bar(stat="identity", width=.90) +
xlab("") + # Set axis labels
ylab("") +
guides(fill=FALSE) +
ggtitle("Number of Turbine Manufacturers by Country") +
theme_minimal()
【问题讨论】: