How to increase the width of the graph in ggplot2?

Below is the plot that I want to include in the document. The problem is that the width of my graph is small (which makes x-axix unreadable at all)

Here is the ggplot2 myCode.r code:

 require("ggplot2") all <- read.csv(file="benchmark/bench.query.csv", head=TRUE, sep=";") w <- subset(all, query %in% c("sort.q1", "sort.q2", "sort.q3", "sort.q4", "sort.q5")) w$rtime <- as.numeric(sub(",", ".", w$rtime, fixed=TRUE)) p <- ggplot(data=w, aes(x=query, y=rtime, colour=triplestore, shape=triplestore)) p <- p + scale_shape_manual(values = 0:length(unique(w$triplestore))) p <- p + geom_point(size=4) p <- p + geom_line(size=1,aes(group=triplestore)) p <- p + labs(x = "Requêtes", y = "Temps d'exécution (log10(ms))") p <- p + scale_fill_continuous(guide = guide_legend(title = NULL)) p <- p + facet_grid(trace~type) p <- p + theme_bw() ggsave(file="bench_query_sort.pdf") print (p) 

I will see how to increase the plot, but I did not find anything.

Any idea on what to add / remove / change in my code?

plot

+5
source share
1 answer

Probably the easiest way to do this is to use graphics devices (png, jpeg, bmp, tiff). You can set the exact width and height of the image as follows:

 png(filename="bench_query_sort.png", width=600, height=600) ggplot(data=w, aes(x=query, y=rtime, colour=triplestore, shape=triplestore)) + scale_shape_manual(values = 0:length(unique(w$triplestore))) + geom_point(size=4) + geom_line(size=1,aes(group=triplestore)) + labs(x = "Requêtes", y = "Temps d'exécution (log10(ms))") + scale_fill_continuous(guide = guide_legend(title = NULL)) + facet_grid(trace~type) + theme_bw() dev.off() 

width and height are in pixels. This is especially useful when preparing images for publication on the Internet. For more information, see the man page with ?png .

Alternatively, you can also use ggsave to get the exact dimensions you want. You can set the dimensions with:

 ggsave(file="bench_query_sort.pdf", width=4, height=4, dpi=300) 

width and height are in inches, and dpi you can set the image quality.

+10
source

All Articles