- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 rpy2-2.0.7(我需要它与 Windows 7 一起使用,并且为较新的 rpy2 版本编译二进制文件是一团糟)将两列数据帧插入 r,在 ggplot2 中创建几个层, 并将图像输出到 <.png> 中。
我已经浪费了无数个小时来研究语法;我确实设法在某一时刻输出了我需要的文件,但是(愚蠢地)没有注意到并继续摆弄我的代码......
如果有任何帮助,我将不胜感激;下面是一个(简单的)演示示例。非常感谢您的帮助!!! ~ 埃里克黄油
import rpy2.robjects as rob
from rpy2.robjects import r
import rpy2.rlike.container as rlc
from array import array
r.library("grDevices") # import r graphics package with rpy2
r.library("lattice")
r.library("ggplot2")
r.library("reshape")
picpath = 'foo.png'
d1 = ["cat","dog","mouse"]
d2 = array('f',[1.0,2.0,3.0])
nums = rob.RVector(d2)
name = rob.StrVector(d1)
tl = rlc.TaggedList([nums, name], tags = ('nums', 'name'))
dataf = rob.RDataFrame(tl)
## r['png'](file=picpath, width=300, height=300)
## r['ggplot'](data=dataf)+r['aes_string'](x='nums')+r['geom_bar'](fill='name')+r['stat_bin'](binwidth=0.1)
r['ggplot'](data=dataf)
r['aes_string'](x='nums')
r['geom_bar'](fill='name')
r['stat_bin'](binwidth=0.1)
r['ggsave']()
## r['dev.off']()
*输出只是一张空白图像 (181 b)。
这是我在 ggplot2 中摆弄时 R 本身抛出的几个常见错误:
r['png'](file=picpath, width=300, height=300)
r['ggplot']()
r['layer'](dataf, x=nums, fill=name, geom="bar")
r['geom_histogram']()
r['stat_bin'](binwidth=0.1)
r['ggsave'](file=picpath)
r['dev.off']()
*RRuntimeError: 错误:绘图中没有图层
r['png'](file=picpath, width=300, height=300)
r['ggplot'](data=dataf)
r['aes'](geom="bar")
r['geom_bar'](x=nums, fill=name)
r['stat_bin'](binwidth=0.1)
r['ggsave'](file=picpath)
r['dev.off']()
*RRuntimeError: 错误:当设置 美学时,它们可能只取一个值。问题:填充,x
最佳答案
我仅通过 Nathaniel Smith 出色的小模块 rnumpy 使用 rpy2 (请参阅 rnumpy 主页上的“API”链接)。有了它,您可以:
from rnumpy import *
r.library("ggplot2")
picpath = 'foo.png'
name = ["cat","dog","mouse"]
nums = [1.0,2.0,3.0]
r["dataf"] = r.data_frame(name=name, nums=nums)
r("p <- ggplot(dataf, aes(name, nums, fill=name)) + geom_bar(stat='identity')")
r.ggsave(picpath)
(我有点猜测你希望情节看起来如何,但你明白了。)
另一个非常方便的方法是使用 ipy_rnumpy 模块从 Python 进入“R 模式”。 (请参阅 rnumpy 主页上的“IPython 集成”链接)。
对于复杂的东西,我通常会在 R 中制作原型(prototype),直到我制定出绘图命令为止。 rpy2 或 rnumpy 中的错误报告可能会变得非常困惑。
例如,赋值(或其他计算)的结果有时会打印出来,即使它应该是不可见的。这很烦人,例如分配给大数据帧时。一个快速的解决方法是用一个评估结果很短的尾随语句结束有问题的行。例如:
In [59] R> long <- 1:20
Out[59] R>
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[19] 19 20
In [60] R> long <- 1:100; 0
Out[60] R> [1] 0
(为了消除 rnumpy 中一些反复出现的警告,我编辑了 rnumpy.py 以添加“from warnings import warn”并将“print”error in process_revents: ignored“”替换为“warn(”error in process_revents: ignored” )'。这样一来,每个 session 我只会看到一次警告。)
关于python - ggplot2 hell 与 rpy2-2.0.7 + python 2.6 + r 2.11 (windows 7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3515269/
我正在从事密室逃脱项目。实际上,我试图创建的行为如下: 网络浏览器以通常的方式显示网络应用程序的一部分。从此时起,客户端上将不再有键盘/鼠标的输入。我已经使用 JS 解决了基于时间的更改,因此我可以加
背景 我试图使用 netatalk创建 Time Capsule使用 Raspberry Pi 3 ,按照教程here .部分版本信息: netatalk 3.1.12 macOS 10.14.5 树
目标:将i2c时钟频率更改为400 khz。动机:试图通过i2c使用Adafruit BNO085,但RPI i2c时钟伸展存在已知问题。(这是一个已知的漏洞,自2012年以来一直在传播)。。我一直在
我正在尝试编写一个小脚本来基于两个因素控制两个树莓派的 gpio 输出引脚:GPIO.input.17 的状态和一天中的时间。 我希望 gpio.output.23 和 gpio.output.25
拥有运行Docker 17.11.0-ce和Docker Compose 1.17.1的RaspberryPi。 我有一个包含两个容器的docker-compose文件,都将restart-polic
我正在尝试使用 Raspbian 在 Raspberry Pi 3 上从另一个 python 脚本运行 python 脚本。几个小时以来,我一直在努力寻找方法来做到这一点,但没有找到任何有效的方法。我
我想通过 Python 使用 R。我想知道要安装哪个版本的 rpy,文档中并不清楚。 我使用的是 OSX 10.5 (leopard) 的 Mac。 我使用Python 2.7版本。 感谢您的帮助!
我在qtdesigner中设计了一个表单。它具有“开”和“关”按钮。开按钮应该开始闪烁,而关按钮应该停止它。因此,如果time.sleep持续时间很短,那没有问题,但是当我写10秒钟的 sleep 时
当我尝试运行应用程序时(只是一个简单的hello_world.c不起作用),每次都会收到此错误: mpiexec -ckpointlib blcr -ckpoint-prefix /tmp/ -ckp
所以我正在尝试设计一个 LCD 屏幕,它有一个菜单和一堆不同的功能,并且它应该有 4 个按钮。选择、菜单以及向上和向下。现在我只是想处理菜单按钮。我希望它始终显示时钟,除非按下菜单按钮。但是当我按下按
我按照此处的说明在我的 Raspberry Pi 上成功安装了 Keras: https://medium.com/@abhizcc/installing-latest-tensor-flow-and
这里的真正目标是在Python中找到分位数平均值(或总和,或中位数等)。由于我不是 Python 的高级用户,但已经使用 R 一段时间了,所以我选择的路线是通过 Rpy。但是,我遇到了以下问题:返回的
在多处理环境中调用 RPy 函数是否安全?关于 RPy 是否存在任何应该注意的多处理问题? 一个简单的例子如下: from multiprocessing import Pool from rpy i
我正在开发一个将 Android 设备与 Raspberry Pi 连接起来的项目。 RPi 需要被视为用户永远不需要触摸的可部署设备。出于这个原因,我正在尝试在 RPi 上编写一个启动批处理脚本,允
我正在尝试从服务器向客户端发送数据字节,因此我使用文件指针来指向文件已读取的位置并读取字节集并将其发送到客户端。 下面是服务器端 byte[] b = readByte()// my function
我正在尝试将 MySQL 数据库从我的 Raspberry Pi 重新定位到我的外部硬盘驱动器,以便我可以保留更大的数据库。我对此知之甚少,所以如果这个问题太简单,我深表歉意,但这些是我迄今为止所采取
我被 Python 包中的 wait_for_edge 函数卡住了 RPi .我为下降的 gpio 添加了多个事件检测,只要回调函数不包含像 os.system("mpc pause") 然后脚本崩
我尝试在 Raspberry Pi 上升级现有的 JDK8,但失败了。 我从oracle网站下载了ARM版本,在Windows中解压,通过FTP传输到我的pi上,然后复制到/usr/local。 然后
我的代码是这样的 package me.Andrew.Keypad.Listener; import java.util.HashMap; import com.pi4j.io.gpio.GpioCo
编写脚本保存在闪存驱动器上,用于更新多个树莓派上的代码。我的想法是,我将目录从树莓派 sd 卡备份到闪存驱动器,然后将新文件从闪存驱动器复制到 pi 中的 sd 卡。 我得到的行为是所有内容都从闪存移
我是一名优秀的程序员,十分优秀!