![]() |
The open-source tool ggplot2 in R is used for statistical data visualization. To make the plots made by ggplot2 more appealing and to apply colors, different designs, and styling ggthemr Package in R is a great help. ggthemr Package in R Programming Language is developed by Ciarán Tobin and maintained by Mikata Project. The idea behind this package is to set the theme once so that there’s no need to update the styling again and again. The theme has several parts:
Installing the ggthemr Package in RTo use this package, we need to install it using: R
Output: ![]() ggthemr Package in R On some versions of R there might be a warning like this. If you also see the same warning, you need to install the different version of the package using. R
Output: ![]() ggthemr Package in R The ‘remotes’ package is used to fetch packages from various sources like GitHub.
Using ggthemr Package in R with ‘ggplot2’Now that the package is installed and loaded, let’s use it with the ggplot2 for changing the color scheme.
To do that just use any of the above themes with ggthemr: R
Output: ![]() ggthemr Package in R From now onwards any plot created using ggplot2 will have the same theme ‘lilac’. For resetting it to default ggplot2 settings, use: R
‘flat dark’ theme in ggthemr Package in RR
Output: ![]() ggthemr Package in R Custom Palettes in ggthemr Package in Rdefine_palette( ) can be used to make customized theme and then can be passed to ggthemr similar to above palettes. R
Output: ![]() Custom color palette in ggthemr Here with the use of define_palette( ) we are using colors from defined random_colors in swatch which takes a vector of color codes. Then gradient takes two values- lower and upper and is used to specify gradient of colors for any required continuous variables in the plot if available. Then simply take sample data and plot a graph with ggplot2. Sky Theme in ggthemr Package in RR
Output: ![]() ggthemr Package in R let’s use the mtcars dataset in the ggplot2 package to make scatter plot.R
Output: ![]() ggthemr Package in R Adding Size, color, and shape and then plotting .R
Output: ![]() ggthemr Package in R Adding color and shape in ggthemr Package in RR
Output: ![]() ggthemr Package in R Conclusion: In this article, we have seen ways to change color scheme of plots that are plotted with ggplot2 using the package ggthemr. In this way more advanced plots plotted using ggplot2 can look good aesthetically and they are easy for understanding too! |
Reffered: https://www.geeksforgeeks.org
R Language |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |