当前位置:网站首页>R语言怎么绘图(一个r语言完整的命令有什么)
R语言怎么绘图(一个r语言完整的命令有什么)
2022-07-30 10:31:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
使用系统:centos 6.4 64bit
在R语言中可以使用png()等函数生成图片,例如: png(“aa.png”)可以生成图片。
但是如果你是通过shell远程连接到系统上,可能会碰到如下错误:
> png(“aa.png”)
错误于.External2(C_X11, paste(“png::”, filename, sep = “”), g$width, :
无法打开PNG设备
此外: 警告信息:
In png(“aa.png”) : 无法打开链结到X11显示”
分析:
打开R控制台,输入capabilities(),可以看到:
> capabilities()
jpeg png tiff tcltk X11 aqua http/ftp sockets
FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE
libxml fifo cledit iconv NLS profmem cairo
TRUE TRUE TRUE TRUE TRUE FALSE FALSE
可以看到png为false,因为生成图片需要X11,但是shell是没有X11的。
怎么解决:
1.在X11模式下执行R语言命令,也就是在linux的桌面。如果你只是在桌面上画画图,那选择这个方式就可以了。
2.不使用X11生成,使用 图形渲染库Cairo。比如我,需要用脚本,根据实时数据生成统计图,那么用这个方式就很方便。
安装:
启动R控制台
安装
install.packages(“Cairo”)
会让你选择安装镜像
— 在此連線階段时请选用CRAN的鏡子 —
CRAN mirror
1: 0-Cloud 2: Argentina (La Plata)
3: Argentina (Mendoza) 4: Australia (Canberra)
5: Australia (Melbourne) 6: Austria
7: Belgium 8: Brazil (BA)
9: Brazil (PR) 10: Brazil (RJ)
11: Brazil (SP 1) 12: Brazil (SP 2)
13: Canada (BC) 14: Canada (NS)
15: Canada (ON) 16: Canada (QC 1)
17: Canada (QC 2) 18: Chile
19: China (Beijing 1) 20: China (Beijing 2)
选一个北京的好了:20
安装出错
configure: error: Cannot find cairo.h! Please install cairo (http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS correspondingly.
所以我们需要先在系统中安装cairo库
yum -y install cairo* libxt*
安装完成之后,重新执行:install.packages(“Cairo”)
installing to /usr/local/lib64/R/library/Cairo/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (Cairo)
下载的程序包在
‘/tmp/RtmpNlGyf3/downloaded_packages’里
更新’.Library’里的HTML程序包列表
Making ‘packages.html’ … 做完了。
安装成功。
加载Cairo后,查看支持:
> library(Cairo)
> Cairo.capabilities()
png jpeg tiff pdf svg ps x11 win raster
TRUE FALSE FALSE TRUE TRUE TRUE TRUE FALSE TRUE
说明已经支持用cairo生成图片了。
例如可以使用如下命令生成PNG:
CairoPNG(file=”out.png”,width=800,height=480)
附上一个测试小程序,主要为了说明用法:
#vim test.r
library(Cairo)
CairoPNG(file=”out.png”,width=800,height=480)
plot(5,4)
保存后执行:
[[email protected] ~]# Rscript test.r
R version 3.1.0 (2014-04-10) — “Spring Dance”
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)
> library(Cairo)
> CairoPNG(file=”out.png”,width=800,height=480)
> plot(5,4)
>
在当前目录下可以看到生成了图片
[[email protected] ~]# ll
总用量 84
-rw-r–r–. 1 root root 6832 5月 13 10:33 out.png
-rw-r–r–. 1 root root 71 5月 13 10:32 test.r
到此这篇关于linux命令行下使用R语言绘图实例讲解的文章就介绍到这了,更多相关linux命令行下使用R语言绘图内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:R语言绘制空间热力图实例讲解
R语言实现对数据框按某一列分组求组内平均值
R语言写2048游戏实例讲解
R语言归一化处理实例讲解
R语言的xtabs函数实例讲解
R语言基本语法深入讲解
R语言 用均值替换、回归插补及多重插补进行插补的操作
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/129476.html原文链接:https://javaforall.cn
边栏推荐
- Linux内核设计与实现(十)| 页高速缓存和页回写
- @RequestBody 和 @ResponseBody 详解
- 【AGC】增长服务2-应用内消息示例
- 鸿湖万联扬帆富设备开发板正式合入OpenHarmony主干
- Online target drone prompt.ml
- 论文阅读:SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers
- Oracle中SQL语言和分页rownum分析
- BERT预训练模型系列总结
- MySQL |子查询
- Detailed explanation of JVM memory layout, class loading mechanism and garbage collection mechanism
猜你喜欢

4、yolov5-6.0 ERROR: AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘ 解决方案
![[AGC] Growth Service 2 - In-App Message Example](/img/fa/9190e45c1532aec908a6c68706629a.png)
[AGC] Growth Service 2 - In-App Message Example

梅科尔工作室-看鸿蒙设备开发实战笔记七——网络应用开发

Adaptive Control - Simulation Experiment 1 Designing Adaptive Laws Using Lyapunov's Stability Theory

Verilog之数码管译码

张量篇-初步

(***Key points***) Flink common memory problems and tuning guide (1)

log4js入门

JCL 学习

Meikle Studio-Look at the actual combat notes of Hongmeng device development six-wireless networking development
随机推荐
Practical Walkthrough | Calculate Daily Average Date or Time Interval in MySQL
【AGC】增长服务2-应用内消息示例
If someone asks you about distributed transactions again, throw this to him
2022年顶会accepted papers list
【C和指针第七章】可变参数列表
Meikle Studio-Look at Hongmeng Device Development Practical Notes 7-Network Application Development
现在报PMP还来得及参加9月的考试吗?分享敏捷全真模拟题
Meikle Studio-Look at the actual combat notes of Hongmeng device development six-wireless networking development
Security tip: FreeType in Qt
【HMS core】【Analytics Kit】【FAQ】如何解决华为分析付费分析中付款金额显示为0的问题?
梅科尔工作室-看鸿蒙设备开发实战笔记七——网络应用开发
Soft Exam System Architect Concise Tutorial | Case Analysis | Requirement Analysis
mysql与redis 区别
Scrapy爬虫之网站图片爬取
Easy gene: human tRNA gene loci showed age-related high DNA methylation | research articles
关于verilog的时延研究
Linux内核设计与实现(十)| 页高速缓存和页回写
第3章 信息收集
Do you really understand the 5 basic data structures of Redis?
MySQL | Subqueries