2
我正在嘗試構建一個水平條形圖。coord_flip()混合軸標籤?
library(ggplot2)
library(plyr)
salary <- read.csv('September 15 2015 Salary Information - Alphabetical.csv', na.strings = '')
head(salary)
salary$X <- NULL
salary$X.1 <- NULL
salary$Club <- as.factor(salary$Club)
levels(salary$Club)
salary$Base.Salary <- gsub(',', '', salary$Base.Salary)
salary$Base.Salary <- as.numeric(as.character(salary$Base.Salary))
salary$Base.Salary <- salary$Base.Salary/1000000
salary <- ddply(salary, .(Club), transform, pos = cumsum(Base.Salary) - (0.5 * Base.Salary))
ggplot(salary, aes(x = Club, y = Base.Salary, fill = Base.Salary)) +
geom_bar(stat = 'identity') +
ylab('Base Salary in millions of dollars') +
theme(axis.title.y = element_blank()) +
coord_flip() +
geom_text(data = subset(salary, Base.Salary > 2), aes(label = Last.Name, y = pos))
(學分此主題:Showing data values on stacked bar chart in ggplot2文本位置計算)
我一會兒徹底糊塗了,因爲我用xlab
指定標籤,並且theme(axis.title.y = element_blank())
隱藏y標籤。但是,這沒有奏效,我通過將其更改爲ylab
來實現。這似乎相當混亂,是否有意?