Error saying cannot open file file pdf when trying to save a plot in ggplot

+1 vote

When I try to save a plot made using ggplot as a pdf using this code:

library(ggplot2)

file = "/data/mda/20150630-1Mb-full_comparison-low_depth_hTERT/result/comparison_figure/SD_rank_custom.csv"
figure_file = "/data/mda/20150604-1Mb-full_comparison-low_depth_hTERT/result/comparison_figure/SD_rank_custom.pdf"

sd_data <- as.data.frame(read.csv(file, header=TRUE))

# generate box plot
ggplot(
    data=sd_data,
    aes(
        x=Experiment, 
        y=SD
    )
)+  
theme_bw() + #use bw theme
geom_boxplot(outlier.shape = NA) + #hide outlier points
geom_jitter() + 
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))   

ggsave(
  filename=figure_file,
  width=10,
  height=10
)

I get the following error:

Error in grDevices::pdf(..., version = version) :
cannot open file 'file.pdf'
Calls: ggsave -> device ->
Execution halted
Nov 9, 2018 in Data Analytics by Ali
• 11,360 points
8,006 views

1 answer to this question.

0 votes

You could try adding the following line of code:

dir.create(file.path(dirname(figure_file)))

It will create the directory for you.

answered Nov 9, 2018 by Maverick
• 10,840 points

Related Questions In Data Analytics

0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

Creating barplot with standard errors plotted in R

For df1 plot # Group data by when ...READ MORE

answered Nov 12, 2018 in Data Analytics by Maverick
• 10,840 points
1,180 views
0 votes
1 answer

": cannot open the connection" Error in R

There can be two reasons for this ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 52,350 points
5,076 views
+2 votes
1 answer

“subscript out of bounds” Error in r programming

This error is likely to occur when ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 52,350 points
9,570 views
+1 vote
1 answer

What does “replacement has” Error mean?

This error occurs when one tries to ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 52,350 points
694 views
0 votes
1 answer

Error saying " cannot open the connection" when trying to install a package in R

Try install.packages(“package_name”, repos="http://cr ...READ MORE

answered Nov 26, 2018 in Data Analytics by Maverick
• 10,840 points
9,160 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP