Modifying the appearance of axes labels

 The theme method can also be modified to use to modify the appearance of the axis labels by just using axes.text as a parameter, as the first argument of this method. The parameters color and angle can be changed for axes labels also. 

R




#creating the plot
#assigning groups based on col2 values
#highlighting the rectangular based area
ggplot(data_frame, aes(col1, col3, colour=col2)) +
       geom_point() +
        theme(axis.text = element_text( color="blue", angle = 90))


Output : 

Working with Axes in R using ggplot2

Working with Axes in R using ggplot2

The ggplot2 package is a powerful and widely used package for graphic visualization. It can be used to provide a lot of aesthetic mappings to the plotted graphs. This package is widely available in the R Programming Language. The package can be downloaded and installed into the working space using the following command.

install.packages("ggplot2")

The ggplot method can be used to create a ggplot object. The graphical object is used to create plots by providing the data and its respective points. The data can be plotted using both points as well as lines.

Syntax : ggplot(data, aes = )

Arguments :

data – The data to be plotted
aes – The aesthetic mappings

The geom_point method can be used to plot the data points on the existing visualization that has been created. The color has been assigned based on the grouping values assigned in the col2 of the data plane in the following code snippet.

That is since there are three groups a, b, and c three different colors are used to denote the values contained in these three groups. These parameters are specified in the aesthetic mappings, as discussed above in the ggplot method.

R




#installing the required libraries
library("ggplot2")
#creating a data frame
data_frame = data.frame(col1 = c(1,4,2,5,6,9,5,3,6,3),
                        col2 = c("a","b","a","c","b","b","b","a","c","a"),
                        col3 = c(3,2,4,2,1,4,8,6,4,2))
#creating the plot
#assigning groups based on col2 values
ggplot(data_frame, aes(col1, col3, colour=col2)) + geom_point()


Output

Working with Axes in R using ggplot2

Similar Reads

Assigning labels to the axes

...

Annotate text on plot

The labels of the x-axis and y-axis of the plotted graph can be changed or customized using the various methods available in the ggplot2 package. The xlab component, which can be added to the plot that is constructed is used to add a customized title to the x-axis and similarly, the ylab method can be used to add a customized text label to the y-axis respectively....

Annotating the Graph with the plotted area

...

Setting axes limits

The plot that has been created using the ggplot2 method can also be annotated with various text items and their corresponding positions can be specified. For example, the text point at any respective coordinates of the x-cord and y-cord can be used to be labeled by a specific text value in the following code snippet the data point at the location 5,2 is labeled with the name “PT1”. The annotate method has the following syntax....

Modifying the axes titles’ appearance

...

Modifying the appearance of axes labels

The graph can also be plotted with a rectangular area or a square area depending on the x-coordinates starting and ending as well as y-coordinates starting and ending. In order to construct a rectangle or a square over that area. Depending upon the respective area that is enclosed within it. The same annotate method can be used with the first parameter specifying “rect” instead of text. In order to plot a rectangle, we can use the following syntax...

Creating an Enhanced Scatter Plot with ggplot2

...