如何改善ggplot2中的锯齿线图? [英] How to improve jagged line graph in ggplot2?

查看:1034
本文介绍了如何改善ggplot2中的锯齿线图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他们的任何过程是否可以改善由geom_line()将ggplot2中的多个点合并为光滑的可展示线条所产生的锯齿线?

Is their any process to improve jagged lines produced by geom_line() joining multiple points into smooth presentable lines in ggplot2?

     lai.se <- structure(list(DOS = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L), .Label = c("D1", "D2", "D3"), class = "factor"), 
    DAS = c(31L, 84L, 113L, 132L, 160L, 35L, 82L, 108L, 126L, 
    146L, 37L, 83L, 94L, 113L, 134L), N = c(24L, 24L, 24L, 24L, 
    24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L), LAI = c(1.5879167, 
    4.3241667, 3.70375, 2.9704167, 0.1879167, 1.7679167, 3.7670833, 
    3.4104167, 2.7879167, 0.195, 1.3179167, 3.5233333, 3.1604167, 
    2.45875, 0.2758333), sd = c(0.4276323, 0.32478644, 0.34151596, 
    0.3338638, 0.09868611, 0.18551876, 0.38212767, 0.31431747, 
    0.35024189, 0.08836682, 0.16378616, 0.29256982, 0.28257326, 
    0.44131535, 0.09536733), se = c(0.08729008, 0.06629675, 0.06971165, 
    0.06814966, 0.02014422, 0.03786886, 0.07800148, 0.06415978, 
    0.07149283, 0.0180378, 0.03343271, 0.05972057, 0.05768002, 
    0.09008312, 0.01946677), ci = c(0.18057328, 0.13714529, 0.14420954, 
    0.14097832, 0.04167149, 0.0783377, 0.16135836, 0.13272463, 
    0.14789418, 0.03731404, 0.06916083, 0.1235414, 0.11932022, 
    0.18635113, 0.04027009)), .Names = c("DOS", "DAS", "N", "LAI", 
"sd", "se", "ci"), class = "data.frame", row.names = c(NA, -15L
))
    ggplot(lai.se, aes(x=DAS, y=LAI, colour=DOS)) + 
  geom_errorbar(aes(ymin=LAI-se, ymax=LAI+se), colour ="black", size =.5, width=1, position=position_dodge(.9)) +
  geom_line() +
  geom_point()+ theme_bw()

使用这些代码创建的线条非常像素化锯齿线。他们是否有任何出路去绘制更平滑的solid行(不是锯齿状的外观)?

Lines created using these codes were very much pixelated zig-zag lines. Is their any way out to plot smoother "solid" lines (not zig-zag looking)?

   > sessionInfo()
R version 2.14.2 (2012-02-29)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_India.1252  LC_CTYPE=English_India.1252    LC_MONETARY=English_India.1252 LC_NUMERIC=C                  
[5] LC_TIME=English_India.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_0.9.2.1

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2       grid_2.14.2        gtable_0.1.1       labeling_0.1      
 [7] MASS_7.3-17        memoise_0.1        munsell_0.4        plyr_1.7.1         proto_0.3-9.2      RColorBrewer_1.0-5
[13] reshape2_1.2.1     scales_0.2.2       stringr_0.6.1      tools_2.14.2    


推荐答案

将图形输出为以矢量格式存储的文件,例如PDF或PostScript,以及然后使用 ImageMagick 或类似方法将该矢量图像渲染为位图(PNG,JPEG等) 。):高分辨率(150,300或甚至600 dpi):

Output your graph to a file stored in a vector format, such as PDF or PostScript, and then use ImageMagick or similar to render that vector image to a bitmap (PNG, JPEG, etc.) at high resolution (150, 300 or even 600 dpi):

$ convert myGraphAsVector.pdf -density 300 myGraphAs300DpiBitmap.png

文件大小将会很大(并且随着您增加最终产品的分辨率而变得越来越大) ,但位图的锯齿似乎会以更高的像素密度消失。

The file size will be large (and get increasingly larger as you increase the resolution of the final product), but the jaggedness of the bitmap will appear to go away at higher pixel densities.

这篇关于如何改善ggplot2中的锯齿线图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆