循环绘制并保存PDF文件 [英] Plotting and saving PDFs in a loop

查看:159
本文介绍了循环绘制并保存PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  head(final_melt)
$ b我有一个半融化的数据框,看起来像这样: $ b组来源变量值
控制全肾MZF1 0.23879
控制全肾MZF1 0.49381
控制全肾MZF1 0.40827
控制全肾MZF1 0.55548
控制全肾MZF1 0.34664
控制整个肾脏MZF1 0.68102

组有两个级别(Control和Disease)具有4个水平(全肾,肾小球,Tubulointerstitium和HK-2 + TGF-B)。变量也有四个级别(TFAP2A,MZF1,YY1,SP1)。
我想在循环中做如下的事情:

  d = subset(final_melt,final_melt $ Source = =Whole Kidney)
qplot(data = d,Group,value,facets =。〜variable,geom =boxplot)
pdf(Whole Kideny.pdf)
dev .off()

虽然我知道我可以说 facets = Source〜变量,个别情节最终太小而不能提供信息。所以我需要一次绘制Source级别的一个级别。

问题是我甚至无法获得 pdf()函数工作。它使用正确的名称创建一个文件,但是当我尝试打开它时,adobe说打开文件时出错,并且它已经在另一个应用程序中打开(为什么我添加了 dev.off (),但这似乎没有做任何事情)。



任何帮助表示赞赏。

干杯,
Davy。

解决方案


  1. 打开图形设备( pdf () png()等)

  2. 创建 < a href =http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f =nofollow> print your ggplot或lattice图形。

  3. 调用 dev.off()
  4. ...
  5. ...






    $ <$> b

    I have a semi-melted data frame that looks like this:

    head(final_melt)
    
       Group       Source variable   value
     Control Whole Kidney     MZF1 0.23879
     Control Whole Kidney     MZF1 0.49381
     Control Whole Kidney     MZF1 0.40827
     Control Whole Kidney     MZF1 0.55548
     Control Whole Kidney     MZF1 0.34664
     Control Whole Kidney     MZF1 0.68102
    

    Group has two levels (Control and Disease), source has 4 levels (Whole Kidney, Glomerulus, Tubulointerstitium, and HK-2 + TGF-B). variable also has four levels (TFAP2A, MZF1, YY1, SP1). I would like to do something like the following in a loop

    d = subset(final_melt, final_melt$Source=="Whole Kidney")
    qplot(data=d, Group, value, facets=.~variable, geom="boxplot")
    pdf("Whole Kideny.pdf")
    dev.off()
    

    While I know I could just say facets=Source~variable, the individual plots end up being too small to be informative. So I need to plot one level of the Source factor at a time.
    The problem is I can't even get the pdf() function to work. It creates a file, with the correct name, but when I try to open it adobe says There was an error opening the file, and that it is already open in another application (why I added the dev.off(), but that didn't seem to do anything).

    Any help is appreciated.
    Cheers, Davy.

    解决方案

    1. Open a graphics device (pdf(), png() etc.)
    2. Create and print your ggplot or lattice graphic.
    3. Call dev.off().
    4. .....?
    5. Profit.

    In that order.

    这篇关于循环绘制并保存PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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