如何从 R 命令行保存直方图
我正在尝试将直方图从我的虚拟机保存到 R 中的文件中。
我使用以下 R 代码:
> pdf("graph1.pdf")
> hist(nchar(as.character(m1$qf)),main="First name search 11-14 and 11-15",
xlab="length of name")
> dev.off()
null device
1
我得到响应: null device 1
如果我只是运行 hist(nchar(as.character(m1$qf)),main="First name search 11-14 和 11-15",xlab="名称长度")
在命令行中我看到了正确的直方图。
但是当保存为 pdf 时,我得到的东西看起来像这样:
ET
BT
/F2 1 Tf 0.00 12.00 -12.00 0.00 41.76 160.01 Tm (500000) Tj
ET
BT
/F2 1 Tf 0.00 12.00 -12.00 0.00 41.76 249.50 Tm (1000000) Tj
ET
BT
/F2 1 Tf 0.00 12.00 -12.00 0.00 41.76 342.32 Tm (1500000) Tj
ET
Q q 59.04 73.44 414.72 371.52 re W n
0.000 0.000 0.000 RG
0.75 w
[] 0 d
1 J
1 j
10.00 M
74.40 87.20 16.00 156.65 re S
90.40 87.20 16.00 20.71 re S
106.40 87.20 16.00 86.75 re S
这不是我期望的直方图。如何将直方图保存到文件?
I am trying to save a histogram to file in R from my Virtual Machine.
I use the following R code:
> pdf("graph1.pdf")
> hist(nchar(as.character(m1$qf)),main="First name search 11-14 and 11-15",
xlab="length of name")
> dev.off()
null device
1
I get the response: null device 1
If I just run the hist(nchar(as.character(m1$qf)),main="First name search 11-14 and 11-15",xlab="length of name")
in the command line I see the correct histogram.
But when saved to pdf, I get something that looks something like this:
ET
BT
/F2 1 Tf 0.00 12.00 -12.00 0.00 41.76 160.01 Tm (500000) Tj
ET
BT
/F2 1 Tf 0.00 12.00 -12.00 0.00 41.76 249.50 Tm (1000000) Tj
ET
BT
/F2 1 Tf 0.00 12.00 -12.00 0.00 41.76 342.32 Tm (1500000) Tj
ET
Q q 59.04 73.44 414.72 371.52 re W n
0.000 0.000 0.000 RG
0.75 w
[] 0 d
1 J
1 j
10.00 M
74.40 87.20 16.00 156.65 re S
90.40 87.20 16.00 20.71 re S
106.40 87.20 16.00 86.75 re S
That's not the histogram I was expecting. How do I save a histogram to file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不熟悉 R 绘图,我建议您尽早开始使用 ggplot2
If you are new to plotting in R, I recommend getting an early start on ggplot2
R,Rscript,将直方图保存到文件中,例如:
foobar.png
:它会在与包含以下图像的 R 脚本相同的目录中生成
foobar.png
(前提是您在图像编辑器中打开它,而不是文字处理器):R, Rscript, save histogram to file like:
foobar.png
:Which produces a
foobar.png
in the same directory as the R script which contains the below image (provided you open it up in an image editor, not a word processor):