Last active
February 3, 2021 13:19
-
-
Save vicperotti/31793314934fe9dc221268f94476f9b7 to your computer and use it in GitHub Desktop.
GGplot dual axis bar and line graph, with coeff to adjust scale between axes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
coeff <-10000 #the factor to divide one access | |
ggplot(data=hdata2,mapping=aes(x=YearBuilt)) + | |
geom_bar() + | |
geom_line(mapping=aes(x=YearBuilt,y=SalePrice/coeff),stat="summary",fun="mean",color="blue",size=1) + | |
scale_y_continuous( | |
# Features of the first axis | |
name = "Number of Sales", | |
# Add a second axis and specify its features | |
# The labels piece creates whole integers rather than scientific notation | |
sec.axis = sec_axis(~.*coeff, name="Mean Price",labels=function(n){format(n, scientific = FALSE)}), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The data is from...https://www.kaggle.com/c/house-prices-advanced-regression-techniques/data?select=train.csv