library(ggplot2)
dat3 <- data.frame(
Year = factor(c("2010","2011"), levels=c("2010","2011")),
Percent = c(30, 55)
)
dat3
## Year Percent
## 1 2010 30
## 2 2011 55
# 1. Underemployment chart ------------------------------------------------
file.choose()
## [1] "U:\\path hidden\\underemployment_majors_2.csv"
Underemployment_data <- read.csv("U:\\path hidden\\underemployment_majors_2.csv")
Underemployment_data
## Major Underemployment
## 1 P.E. education 56.4
## 2 Human services 55.6
## 3 Illustration 54.7
## 4 Criminal justice 53.0
## 5 Project management 52.8
## 6 Radio/TV/Film production 52.6
## 7 Studio art 52.0
## 8 Healthcare admin 51.8
## 9 Education 51.8
## 10 Human development and family studies 51.5
## 11 Creative writing 51.1
## 12 Animal science 51.1
## 13 Exercise science 51.0
## 14 Health sciences 50.9
## 15 Paralegal studies 50.9
## 16 Theatre 50.8
## 17 Art history 50.7
ggplot(data = Underemployment_data,
aes(x = reorder(Major, Underemployment), y = Underemployment), fill = Major) +
geom_bar(stat="identity", fill = "yellow", color = "dark blue") +
coord_flip(ylim = c(45, 60)) +
xlab("Major")
# 2. Normal column chart --------------------------------------------------------
dat3 <- data.frame(
Year = factor(c("2010","2011"), levels=c("2010","2011")),
Percent = c(30, 55)
)
dat3
## Year Percent
## 1 2010 30
## 2 2011 55
ggplot(data=dat3, aes(x = Year, y = Percent, fill = Year,
label = Percent)) +
geom_bar(colour="black", stat="identity") +
guides(fill=FALSE) +
expand_limits(y=c(0, 60)) +
geom_text(size = 3, position = position_stack(vjust = 1.1)) +
ylab("Revenue Percentage Growth")
#Change y axis range
ggplot(data=dat3, aes(x = Year, y = Percent, fill = Year,
label = Percent)) +
geom_bar(colour="black", stat="identity") +
guides(fill=FALSE) +
expand_limits(y=c(0, 60)) +
geom_text(size = 3, position = position_stack(vjust = 1.1)) +
ylab("Revenue Percentage Growth") +
coord_cartesian(ylim = c(20, 60))
# Bar chart version.
ggplot(data=dat3, aes(x = Year, y = Percent, fill = Year,
label = Percent)) +
geom_bar(colour="black", stat="identity") +
guides(fill=FALSE) +
expand_limits(y=c(0, 60)) +
geom_text(size = 3, position = position_stack(vjust = 1.1)) +
ylab("Revenue Percentage Growth") +
coord_flip()
# Change x axis range.
ggplot(data=dat3, aes(x = Year, y = Percent, fill = Year,
label = Percent)) +
geom_bar(colour="black", stat="identity") +
guides(fill=FALSE) +
expand_limits(y=c(0, 60)) +
geom_text(size = 3, position = position_stack(vjust = 1.1)) +
ylab("Revenue Percentage Growth") +
coord_flip(ylim = c(20,60))
# 3. Column chart considering the number of observations ---------------------------
# make data
dat5 = data.frame(Year=c("2010 ","2011"),
Percent=c(30,55),
Cases=c(500,100))
dat5
## Year Percent Cases
## 1 2010 30 500
## 2 2011 55 100
# Calculate the future positions on the x axis of each bar
dat5$right=cumsum(dat5$Cases)
dat5$left=dat5$right - dat5$Cases
# Plot
ggplot(dat5, aes(ymin = 0)) +
geom_rect(aes(xmin = left, xmax = right, ymax = Percent,
colour = Year, fill = Year)) +
xlab("Number of Units Sold") + ylab("Revenue Percentage Growth")
# 4. Bar chart with 2 y axes ----------------------------------------------
library(highcharter)
## Warning: package 'highcharter' was built under R version 3.4.4
## Highcharts (www.highcharts.com) is a Highsoft software product which is
## not free for commercial and Governmental use
names(dat5)
## [1] "Year" "Percent" "Cases" "right" "left"
dat5
## Year Percent Cases right left
## 1 2010 30 500 500 0
## 2 2011 55 100 600 500
highchart() %>%
hc_yAxis_multiples(
list(lineWidth = 3, lineColor='blue', title=list(text="Revenue Percentage Growth")),
list(lineWidth = 3, lineColor="green", title=list(text="Number of Units Sold"))
) %>%
hc_add_series(data = dat5$Percent, name = "Revenue Percentge Growth", color='blue', type = "column") %>%
hc_add_series(data = dat5$Cases, name = "Number of Units Sold", color='green', type = "column", yAxis = 1) %>%
hc_xAxis(categories = dat5$Year, title = list(text = "Year"))
highchart() %>%
hc_yAxis_multiples(
list(lineWidth = 3, lineColor='yellow', title=list(text="Revenue Percentage Growth")),
list(lineWidth = 3, lineColor="green", title=list(text="Number of Units Sold"))
) %>%
hc_add_series(data = dat5$Percent, name = "Revenue Percentage Growth", color='yellow', type = "column") %>%
hc_add_series(data = dat5$Cases, name = "Number of Units Sold", color='green', type = "column", yAxis = 1) %>%
hc_xAxis(categories = dat5$Year, title = list(text = "Year"))