- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to save a plot as SVG created with ggplot2 in R?
There are multiple ways to save a plot created in R. Base R provides, metafile, bitmap, and postscript options to copy and save the plots created in R but we can also save the plots created with ggplot2 as an SVG file with the help of svglite package. The ggsave function of svglite package does this job easily and we can also define the height and width of the plot inside this function.
Example
Install the svglite package −
install.packages("svglite")
Consider the ToothGrowth data and create a scatterplot between len and dose −
head(ToothGrowth) len supp dose 1 4.2 VC 0.5 2 11.5 VC 0.5 3 7.3 VC 0.5 4 5.8 VC 0.5 5 6.4 VC 0.5 6 10.0 VC 0.5 library(ggplot2) library(svglite) ScatterPlotImage<-ggplot(ToothGrowth,aes(len,dose))+geom_point(size=3) ScatterPlotImage
Output
ggsave(file="Scatter.svg", plot=ScatterPlotImage, width=10, height=10)
This plot will be saved as an SVG in the default folder for your R version as shown above.
- Related Articles
- How to extract data from a plot created by ggplot2 in R?
- How to add a citation in a plot created by using ggplot2 in R?
- How to add a horizontal line to the plot created by ggplot2 in R?
- How to plot a function with ggplot2 in R?
- How to highlight text inside a plot created by ggplot2 using a box in R?
- How to change legend values in a bar plot created by using ggplot2 in R?
- How to display regression slope using model in a plot created by ggplot2 in R?
- How to display regression intercept using model in a plot created by ggplot2 in R?
- How to remove the boxes around legend of a plot created by ggplot2 in R?
- How to save matrix created in R as tables in a text file with column names same as the matrix?
- How to align the text horizontally in a bar plot created by using ggplot2 in R?
- How to make all text size same in a plot created by using ggplot2 in R?
- How to save a plot in pdf in R?
- How to display ID column values in a scatterplot created with ggplot2 in R?
- How to change the angle of annotated text in plot created by using ggplot2 in R?

Advertisements