Below is a plot that I want to include in a paper. The problem is the width of my plot which is to small (that make x-axix not readable at all)
Here is the ggplot2 code myCode.r
:
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've look around to see how to enlarge the plot, but I found nothing.
Any idea about what to add/delete/modify in my code ?
If we want to control the width of our line graphic, we have to specify the size argument within the geom_line function. Have a look at the following R code and the resulting image: Figure 2: ggplot2 Line Graph with Thick Line. As you can see, the previous R syntax increased the size of the lines of our plot.
The following code shows how to make the points in our ggplot2 scatterplot larger. For this, we have to specify a large value to the size argument within the geom_point function. Have a look at the following example code: ggplot (data, aes (x, y)) + # Increase point size geom_point (size = 10)
Our example data consists of ten rows and the two columns x and y. Furthermore, we need to install and load the ggplot2 package to RStudio: Now, we can draw a line plot with default specifications as follows: ggplot ( data, aes ( x, y)) + # Create default line plot geom_line () Figure 1: Default ggplot2 Line Graph.
BarPlot using ggplot2 in R To Increase or Decrease width of Bars of BarPlot, we simply assign one more width parameter to geom_bar () function. We can give values from 0.00 to 1.00 as per our requirements.
Inside a Jupyter notebook I found the following helpful:
# Make plots wider options(repr.plot.width=15, repr.plot.height=8)
Probably the easiest way to do this, is by using the graphics devices (png, jpeg, bmp, tiff). You can set the exact width and height of an 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()
The width
and height
are in pixels. This is especailly useful when preparing images for publishing on the internet. For more info, see the help-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)
The width
and height
are in inches, with dpi
you can set the quality of the image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With