You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ggplot(attrition, aes(x=JobRole, y=MonthlyIncome, fill=Attrition)) +
geom_bar(stat='summary', fun=mean, position='dodge') +#Unstack bars using position = ‘dodge’
coord_flip() #Flip x and y axis
3 Reorder Job Role by highest to lowest Monthly Income
ggplot(attrition, aes(x= reorder(JobRole, MonthlyIncome), y=MonthlyIncome, fill=Attrition)) +
geom_bar(stat='summary', fun=mean, width=.8, position='dodge') +
coord_flip() +
scale_fill_manual(values= c('#96adbd', '#425e72')) +
xlab('') +#Make x label invisible, notice the space between parentheses
ylab('Monthly Income in USD') +#Add y label
ggtitle('Employee Attrition by Job Role & Income') #Add title
6 Add theme
ggplot(attrition, aes(x= reorder(JobRole, MonthlyIncome), y=MonthlyIncome, fill=Attrition)) +
geom_bar(stat='summary', fun=mean, width=.8, position='dodge') +
coord_flip() +
scale_fill_manual(values= c('#96adbd', '#425e72')) +
xlab('') +
ylab('Monthly Income in USD') +
ggtitle('Employee Attrition by Job Role & Income') +
theme_clean() #Adding a theme
7 Remove outlines and minimizing aspect ratio
ggplot(attrition, aes(x= reorder(JobRole, MonthlyIncome), y=MonthlyIncome, fill=Attrition)) +
geom_bar(stat='summary', fun=mean, width=.8, position='dodge') +
coord_flip() +
scale_fill_manual(values= c('#96adbd', '#425e72')) +
xlab('') +
ylab('Monthly Income in USD') +
ggtitle('Employee Attrition by Job Role & Income') +
theme_clean() +
theme(aspect.ratio=.65,
plot.background= element_rect(color='white'),
legend.background= element_rect(color='white')) #Change height and 'remove' outlines
ggplot(attrition, aes(x=MonthlyIncome, y=YearsSinceLastPromotion, color=Attrition)) +
geom_smooth(se=FALSE) #Note that se = FALSE removes the confidence shading
ggplot(attrition, aes(x=MonthlyIncome, y=YearsSinceLastPromotion, color=Attrition)) +
geom_smooth(se=FALSE) +
facet_wrap(WorkLifeBalance~.,
labeller= labeller(WorkLifeBalance=wlb.labs)) +
xlab('Monthly Income') +
ylab('Years Since Last Promotion') +
ggtitle('Attrition by Work-life Balance & Years Since Last Promotion')
5 Add space between labels and tick markers
ggplot(attrition, aes(x=MonthlyIncome, y=YearsSinceLastPromotion, color=Attrition)) +
geom_smooth(se=FALSE) +
facet_wrap(WorkLifeBalance~.,
labeller= labeller(WorkLifeBalance=wlb.labs)) +
xlab('\nMonthly Income') +
ylab('Years Since Last Promotion\n') +
ggtitle('Attrition by Work-life Balance and Promotion')
6 Theme
ggplot(attrition, aes(x=MonthlyIncome, y=YearsSinceLastPromotion, color=Attrition)) +
geom_smooth(se=FALSE) +
facet_wrap(WorkLifeBalance~.,
labeller= labeller(WorkLifeBalance=wlb.labs)) +
xlab('\nMonthly Income') +
ylab('Years Since Last Promotion\n') +
ggtitle('Attrition, Work-life Balance, and Years Last Promoted') +
theme_fivethirtyeight()
7 Override theme default to bring x and y labels back
ggplot(attrition, aes(x=MonthlyIncome, y=YearsSinceLastPromotion, color=Attrition)) +
geom_smooth(se=FALSE) +
facet_wrap(WorkLifeBalance~.,
labeller= labeller(WorkLifeBalance=wlb.labs)) +
xlab('\nMonthly Income') +
ylab('Years Since Last Promotion\n') +
ggtitle('Attrition, Work-life Balance, and Years Last Promoted') +
theme_fivethirtyeight() +
theme(axis.title= element_text()) #Bringing back our x and y labels
8 Add space and change legend location
ggplot(attrition, aes(x=MonthlyIncome, y=YearsSinceLastPromotion, color=Attrition)) +
geom_smooth(se=FALSE) +
facet_wrap(WorkLifeBalance~.,
labeller= labeller(WorkLifeBalance=wlb.labs)) +
xlab('\nMonthly Income') +
ylab('Years Since Last Promotion\n') +
ggtitle('Attrition by Work-life Balance and Promotion') +
theme_fivethirtyeight() +
theme(axis.title= element_text(),
legend.position='top',
legend.justification='left',
panel.spacing= unit(1.5, 'lines'))
9 Change line color
ggplot(attrition, aes(x=MonthlyIncome, y=YearsSinceLastPromotion, color=Attrition)) +
geom_smooth(se=FALSE) +
facet_wrap(WorkLifeBalance~.,
labeller= labeller(WorkLifeBalance=wlb.labs)) +
xlab('\nMonthly Income') +
ylab('Years Since Last Promotion\n') +
ggtitle('Attrition by Work-life Balance and Promotion') +
theme_fivethirtyeight() +
theme(axis.title= element_text(),
legend.position='top',
legend.justification='left',
panel.spacing= unit(1.5, 'lines')) +
scale_color_manual(values= c('#999999','#ffb500')) #Change line color