jo.H jo.H -4 years ago 70
R Question

can't write pdf in R

I try to save a ggplot in a pdf in my wd. The pdf file is created but does not contain anything. Here is what I have :

pdf("enrich_prof_eu.pdf",height = 7,width =10)
par(mfrow=c(1,2),mar=c(4, 4.1, 5.5, 1) +

for (i in el){
df=data.frame(horizon = c("h1", "h2", "h3", "h4"), val =yeubis[,i])
ggplot(df, aes(x=val,y=horizon)) +
geom_point() +
geom_segment(aes(x=df$val[1], y=df$horizon[1], xend=df$val[2],
yend=df$horizon[2])) +
geom_segment(aes(x=df$val[2], y=df$horizon[2], xend=df$val[3],
yend=df$horizon[3])) +
geom_segment(aes(x=df$val[3], y=df$horizon[3], xend=df$val[4],
yend=df$horizon[4])) +
scale_y_discrete(limits = rev(levels(df$horizon)))+
scale_x_continuous(position = "top") +

The loop and the ggplot are working. I don't have any error message. But still I can't open the pdf because nothing is writen in it ?

Thank you for the help!

Answer Source

Don't use pdf() and with ggplot2. Use ggsave()

ggplot(data = df, aes(x, y)) + geom_segment(...)

See ?ggsave for more options, such as output dimensions, units, etc.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download