- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我可以在存储后使用 ggsave 保存绘图,但在管道中使用它时出现以下错误。我希望在同一个(管道)命令中进行绘制和保存。
no applicable method for 'grid.draw' applied to an object of class "c('LayerInstance', 'Layer', 'ggproto', 'gg')"
我知道 ggsave 的参数首先是文件名,然后是绘图,但在包装器中切换它不起作用。另外,在 ggsave 命令中使用“filename=”和“plot=”不起作用。
library(magrittr)
library(ggplot2)
data("diamonds")
# my custom save function
customSave <- function(plot){
ggsave('blaa.bmp', plot)
}
#This works:
p2 <- ggplot(diamonds, aes(x=cut)) + geom_bar()
p2 %>% customSave()
# This doesn't work:
ggplot(diamonds, aes(x=cut)) + geom_bar() %>% customSave()
# and obviously this doesn't work either
ggplot(diamonds, aes(x=cut)) + geom_bar() %>% ggsave('plot.bmp')
最佳答案
正如 akrun 指出的那样,您需要将所有 ggplot 括在括号中。您还可以使用dot notation将对象传递给 magrittr 管道流中第一个以外的函数参数:
library(magrittr)
library(ggplot2)
data("diamonds")
(
ggplot(diamonds, aes(x=cut)) +
geom_bar()
) %>%
ggsave("plot.png", . , dpi = 100, width = 4, height = 4)
关于r - 将 ggsave 与管道一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54648159/
我想知道如何在 superheat 包中使用 ggsave。 ggsave 不起作用...... # install devtools install.packages("devtools") # u
有没有办法在批处理模式下使用ggsave?当我说批处理模式时,我的意思是我首先通过 ggplot 绘制所有图,然后将每个图保存在特定文件夹中。 Here是一个建议称为 的参数 plot=last_pl
有没有办法在批处理模式下使用 ggsave?当我说批处理模式时,我的意思是我首先通过 ggplot 绘制所有绘图,然后将每个绘图保存在特定文件夹中。 Here是一个建议的参数,称为 plot=last
我有下面的例子 library(ggplot2) library(ggthemes) ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour
图书馆(ggplot2) > ggplot(mpg, aes(displ, hwy))+geom_point() > ggsave("try.jpg") 它抛出一个错误 "Saving 6.99 x
每当我使用 ggsave 和 scale 保存绘图时,绘图的大小都会增加,但文本的大小不会。 ggplot(economics, aes(date, unemploy)) + geom_line(
我已经更新了我的 ggplot2 库,现在我遇到了一个问题,在调用 ggsave 后,图形设备不再显示绘图。我无法解决该问题,这意味着我无法根据需要导出图。请帮忙。 在网上搜索发现一些提到 dpi 不
我在更改 ggplot2 的标题大小、X-Y 标签、X-Y 轴文本时遇到问题.我正在使用 ggsave将绘图保存为 jpg。 p <- ggplot() p + theme(axis.title =
我正在保存一个分面 ggplot2 图,它可以很好地以较小的尺寸保存,但当我想增加它时却失败了。 > ggsave("tst.png",height=6.75,width=9) # works fin
我可以在存储后使用 ggsave 保存绘图,但在管道中使用它时出现以下错误。我希望在同一个(管道)命令中进行绘制和保存。 no applicable method for 'grid.draw'
R问题。 我对宽度、高度、dpi 和单位感到非常困惑。 为什么下面两个尺寸不同? ggsave(filename = "foo.png",ggplot(mtcars, aes(x=wt, y=mpg)
不必在每次调用时重复“height= 4, width= 4, dpi= 72”。 。 . 我曾经尝试过库(默认)来解决这样的问题,但它的表现不佳。我在 R-help 上问了一个问题,但似乎没有人使用
我刚开始学习使用 python。我正在使用 anaconda python 3.5 和 Rodeo 来做一个简单的 ggplot。 from ggplot import * df=pd.DataFra
我一直在尝试清理我的项目工作流程,并且一直在使用 here 包,但对某些实用程序感到困惑。 我在文件夹 ~\ProjFolder 中设置了一个 Rstudio 项目。在此文件夹中,我添加了一个 Plo
我想在 ggplot2::ggsave() 中保存 stats::heatmap() 的输出,但输出不是绘图,并且我收到一个错误。 这是代码: data("iris") col<- colorRamp
我使用 ggsave 来保存使用 ggplot2 生成的图形,这就是我的做法 figure1<-last_plot() ggsave(figure1,file="/home/user1/figure1
如何去除ggsave中的白边距? 我的问题和Remove white space (i.e., margins) ggplot2 in R一模一样。然而,那里的答案对我来说并不理想。我不想对固定但未知
我使用 ggplot2::ggsave() 创建了一个 svg。我将 svg 嵌入到一个 html 文件中。但是,我发现 svg 周围有一个边框。如何删除此边框? tl;dr 版本:download
我已经将 ggplot 导入到 python 中并正在运行以下脚本,希望 ggsave() 实际上会将我的绘图保存在某个地方,但它似乎实际上并没有将任何内容写入 .png 文件以供以后使用。当我在我的
我正在尝试在我的本地计算机(12 核 Mac Pro 2009 或 Macbook Pro 2017)中运行 foreach 和 doParallel。一旦出现 plot 或 device-out,例
我是一名优秀的程序员,十分优秀!