我想绘制按字母顺序排序的国家/地区名称,其中阿根廷位于顶部。当我将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()