Need help improving image quality of a plot in ggplot

I have created this plot using ggplot in R and am struggling to get a polished finish:
I exported the file as a JPEG and PNG and it always seems a little pixelated, especially the black circle, is there an easy way to fix this? I would also like to add horizontal lines on the error bars.


Here is the code I used:
theme_classic() )

df <- rdata2
df$SITE <- as.factor(df$SITE)

df.summary <- df %>%
group_by(SITE) %>%
sd = sd(CF, na.rm = TRUE),
CF = mean(CF)

f <- ggplot(
aes(x = SITE, y = CF, ymin = CF-sd, ymax = CF+sd)

ff<- f + geom_pointrange()
ggplot(df, aes(SITE, CF))+
geom_jitter(position = position_jitter(0.2), color = "darkgray") +
geom_pointrange(aes(ymin = CF-sd, ymax = CF+sd),data = df.summary)+labs(title="",x="Where",y = "Condition")

jpg or png always converts the plot into a raster-image, at some point it will always be pixelated, the question is how much is acceptable.
I would suggest to use the ggsave() function, here you can define the output dimensions of the plot, using the width and height arguments (carfully, when just increasing the size the size of points, linewidth, fonts shrinks proportionally and may need adjustment) and the resolution (pixel per area) of the plot using the dpi argument.
Increasing the dpi to 600 or 1200 adds more pixels, decreases the pixelation and increases the file-size.

For the errorbars you can use geom_errorbar().

1 Like

device Device to use. Can either be a device function (e.g. png or one of "eps", "ps", "tex"(pictex), "pdf", "jpeg", "tiff", "png", "bmp", "svg" or "wmf" (windows only).

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.