Increase plot size (width) in ggplot2

后端 未结 2 752
粉色の甜心
粉色の甜心 2020-12-05 11:12

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 c

相关标签:
2条回答
  • 2020-12-05 11:44

    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.

    0 讨论(0)
  • 2020-12-05 11:45

    Inside a Jupyter notebook I found the following helpful:

    # Make plots wider 
    options(repr.plot.width=15, repr.plot.height=8)
    
    0 讨论(0)
提交回复
热议问题