I am learning R and ggplot2 but one thing that really confuses me is the parameters available to the aes function.
I am proficient in programming languages such as Python and Java. In such programming languages you define a function, and its parameters are also pre-defined and you expect so many parameters that a function can take.
But the use of the aes function seems to be very different here, except its 'x' and 'y' parameters. For example:
ggplot(forestarea, aes(income))+geom_bar(aes(fill=region))+ labs(x="Regions", y="Number of countries",
title="Number of countries by income level from each region in the world",
caption="The WDI Forest Area Indicator")
In the above code, in the second aes function, the 'fill' parameter seems to be associated with the 'geom_bar' function. Is it actually a parameter of geom_bar?
Then:
ggplot(forestarea, aes(factor(1), fill= income))+geom_bar()+ coord_polar(theta="y")+ theme(axis.line = element_blank(), panel.background = element_blank()) + theme(axis.text = element_blank()) + theme(axis.ticks = element_blank()) + labs(x=NULL, y=NULL, fill="Income level",
title="Proportion of countries by income level",
caption="WDI Forest Area Indicator")
This code creates a pie chart, but you can see the 'fill' parameter is inside the aes function that is outside the geom_bar function, I am confused. Is it a parameter of aes or not?
Then:
ggplot(land_and_agrpc, aes(area = AG.LND.FRST.K2, fill = AG.LND.AGRI.ZS, label=country)) +
geom_treemap() + geom_treemap_text() +
labs(title="Countries by land area",
fill="% of agriculture land",
caption="WDI country land area and forest land percentage datasets")
This code is used to create a treemap, and you can see the aes function takes the 'area' parameter, which is explained in the documentation for treemap: https://cran.r-project.org/web/packages/treemapify/vignettes/introduction-to-treemapify.html. I am even more confused.
So, how do I interpret the parameters of the aes function, where do I use them (inside 'ggplot', or the 'geom_XXX' function)?