

The theme() function accepts one of the four element_type() functions mentioned above as arguments. Therefore, it can be modified using the theme() function. Plot and axis titles and the axis text are part of the plot’s theme. Let’s discuss a number of tasks related to changing the plot output, starting with modifying the title and axis texts. More on this follows in upcoming discussion. element_blank(): Turns off displaying the theme item.element_rect(): Modifies rectangle components such as plot and panel background.element_line(): Likewise element_line() is use to modify line based components such as the axis lines, major and minor grid lines, etc.element_text(): Since the title, subtitle and captions are textual items, element_text() function is used to set it.The arguments passed to theme() components require to be set using special element_type() functions. Gg <- ggplot(midwest, aes( x=area, y=poptotal)) + geom_point( aes( col=state, size=popdensity)) + geom_smooth( method= "loess", se=F) + xlim( c( 0, 0.1)) + ylim( c( 0, 500000)) + labs( title= "Area Vs Population", y= "Population", x= "Area", caption= "Source: midwest") # midwest <- read.csv("") # bkup data source # Add plot components. Type ?theme in the R console and see for yourself.


Most of the requirements related to look and feel can be achieved using the theme() function.

The below plot has the essential components such as the title, axis labels and legend setup nicely. We have done something similar in the previous ggplot2 tutorial already. The point’s color and size vary based on state (categorical) and popdensity (continuous) columns respectively. Let’s begin with a scatterplot of Population against Area from midwest dataset.
