小编Tum*_*own的帖子

在reshape2中使用min或max时,没有非缺失参数警告

当我在reshape2包中的dcast函数中使用min或max时,我收到以下警告.它告诉我什么?我找不到任何解释警告信息的东西,我有点困惑,为什么我在使用max时得到它而不是当我使用mean或其他聚合函数时.

警告消息:
在.fun(.value [0],...)中:min没有非缺失参数; 返回Inf

这是一个可重复的例子:

data(iris)

library(reshape2)

molten.iris <- melt(iris,id.var="Species")
summary(molten.iris)
str(molten.iris)
#------------------------------------------------------------
# Both return warning:
dcast(data=molten.iris,Species~variable,value.var="value",fun.aggregate=min)
dcast(data=molten.iris,Species~variable,value.var="value",fun.aggregate=max)

# Length looks fine though
dcast(data=molten.iris,Species~variable,value.var="value",fun.aggregate=length)

#------------------------------------------------------------
# No warning messages here:
aggregate(value ~ Species + variable, FUN=min, data=molten.iris)
aggregate(value ~ Species + variable, FUN=max, data=molten.iris)
#------------------------------------------------------------
# Or here:
library(plyr)

ddply(molten.iris,c("Species","variable"),function(df){
  data.frame(
    "min"=min(df$value),
    "max"=max(df$value)
    )
})
#------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

r aggregate-functions reshape2

33
推荐指数
1
解决办法
6万
查看次数

删除ggplot2中的Plot Margins

我正试图在R中使用ggplot2和ggsave(与Cairo)生成一个png图表.我在定制主题以删除边距时遇到问题.

目前我正在使用:

... + theme(plot.margin=unit(c(0,0,0,0),"mm"))      
Run Code Online (Sandbox Code Playgroud)

这似乎适用于我的情节的四个方面中的两个,它完全去除了顶部和右侧边缘,但左侧和底侧仍然有相当大的边距.有没有办法彻底删除这些?下图说明问题:

在此输入图像描述

如果一个可重复的例子是有用的,那么让我知道,我会把它放在一起.


编辑:

library("ggplot2")
library("scales")
library("Cairo")
library("grid")

# Set chart values
line.width = 0.45
axis.font.size = 2.9

# Generate some random data
start.date <- as.Date("2011-07-01")
x.month <-seq.Date(start.date, by = "month", length.out = 24)
end.date <- max(x.month)

period.a <- rnorm(12, mean=50, sd=2)
period.b <- rnorm(12, mean=55, sd=2)

x.value <- c(period.a,period.b)

# Combine into dataframe
x.data <- data.frame(
  "Month" = x.month,
  "Value" = x.value
  )

# Build chart
p <- ggplot(data=x.data, aes(Month, Value)) + geom_line(size=line.width)
p <- …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

25
推荐指数
1
解决办法
3万
查看次数

R Download.File问题与Excel工作簿

我正在尝试使用R的download.file函数下载Excel工作簿.

当我手动下载文件时(使用Internet Explorer或Chrome,右键单击并另存为),然后下载文件,然后我可以在Excel中打开它而不会出现任何问题.

当我在R中使用download.file时,文件会下载并报告正确的文件大小.但是当我尝试在Excel 2010中打开下载的xls文件时,我收到以下错误消息:

Excel在'test.xls'中找到了不可读的内容.你想恢复这个工作簿的内容吗?如果您信任此工作簿的来源,请单击"是".

当我单击是时,没有任何反应.

我也尝试使用R包xlsx直接访问该文件,这也失败了.

excel r download

20
推荐指数
1
解决办法
7073
查看次数

RStudio knitr主题

我刚开始玩RStudio中的一些新的knitr功能.

我已经尝试在R Markdown设置对话框中选择了几个不同的主题,但这些似乎对我生成的文档的样式没有任何明显的影响.应该是,还是我错过了什么?无论我选择什么主题,一切似乎都以默认样式出现.

---
output:
  html_document:
    number_sections: yes
    theme: spacelab
    toc: yes
  pdf_document: default
  word_document: default
---
Run Code Online (Sandbox Code Playgroud)

R Markdown选项 出口结果

安装细节:

  • R版本3.1.1
  • RStudio版本0.98.977
  • knitr 1.6
  • rmarkdown 0.2.50
  • htmltools 0.2.4
  • Windows 7的

r rstudio knitr

12
推荐指数
1
解决办法
1万
查看次数

R exdir不存在错误

我正在尝试使用R下载并解压缩zip文件.每当我这样做时,我都会收到错误消息

解压缩时出错(temp,list = TRUE):'exdir'不存在

我正在使用基于Stack Overflow问题的代码使用R来下载压缩数据文件,提取和导入数据

举一个简化的例子:

# Create a temporary file
temp <- tempfile()

# Download ZIP archive into temporary file
download.file("http://cran.r-project.org/bin/windows/contrib/r-release/ggmap_2.2.zip",temp)

# ZIP is downloaded successfully:

# trying URL 'http://cran.r-project.org/bin/windows/contrib/r-release/ggmap_2.2.zip'
# Content type 'application/zip' length 4533970 bytes (4.3 Mb)
# opened URL
# downloaded 4.3 Mb

# Try to do something with the downloaded file
unzip(temp,list=TRUE)

# Error in unzip(temp, list = TRUE) : 'exdir' does not exist
Run Code Online (Sandbox Code Playgroud)

到目前为止我尝试过的:

  • 手动访问临时文件并使用7zip解压缩:可以做到这一点没有问题,文件存在且可访问.
  • 将临时目录更改为c:\ temp.再次,文件下载成功,我可以访问它并用7zip解压缩,但R在尝试访问它时抛出exdir错误消息.

R版本2.15.2

R-Studio版本0.97.306

编辑:代码工作,如果我使用unz …

r unzip rstudio

8
推荐指数
1
解决办法
8041
查看次数

htmlParse无法加载外部实体

我正在尝试使用R和XML包加载一些公开可用的NHS数据,但我不断收到以下错误消息:

错误:无法加载外部实体" http://www.england.nhs.uk/statistics/statistical-work-areas/bed-availability-and-occupancy/ "

尽管看了一些相关的问题,我似乎无法弄清楚可能导致这种情况的原因.

这是我非常简单的代码:

library("XML")
url <- "http://www.england.nhs.uk/statistics/statistical-work-areas/bed-availability-and-occupancy/"
doc <- htmlParse(url)
Run Code Online (Sandbox Code Playgroud)

编辑:会话信息

R版本3.0.1(2013-05-16)平台:i386-w64-mingw32/i386(32位)

locale:[1] LC_COLLATE = English_United Kingdom.1252 LC_CTYPE = English_United Kingdom.1252 [3] LC_MONETARY = English_United Kingdom.1252 LC_NUMERIC = C [5] LC_TIME = English_United Kingdom.1252

附加基础包:[1] stats graphics grDevices utils
数据集方法库

通过命名空间加载(而不是附加):[1] tools_3.0.1

xml r

7
推荐指数
2
解决办法
8456
查看次数

导致这个ggplot2方面错误的原因是什么?

我正在努力整理一些R演示,向同事展示它的一些功能.我特别希望,让他们感兴趣的ggplot2,因此用小面的一个简单的例子放在一起facet_grid用的iris数据集.

为了向他们展示不同的模式,我想向他们展示使用的产品.~Species,Species~.以及Species~Species(我承认的一个不好的例子).

这似乎引起了一些奇怪的行为ggplot,我想知道为什么会这样.我希望下面的图表包含沿对角线的点,每个轴上的物种名称彼此匹配.相反,所有内容都列在setosax轴下,然后列在y轴的实际物种下.

我意识到这个例子不会出现在任何现实的使用场景中,它只是让我感到有趣的怪癖.为什么会ggplot这样?

我也尝试使用mtcars数据集并获得相同的效果.

library("ggplot2")
data(iris)
ggplot(iris, aes(Petal.Width, Petal.Length, colour=Species)) +
  geom_point() +
  theme_bw() +
  facet_grid(Species~Species)
Run Code Online (Sandbox Code Playgroud)

ggplot刻面散点图显示bug

plot r ggplot2

6
推荐指数
1
解决办法
327
查看次数

knitr R markdown文档中的mapview错误

我一直在玩mapview包,最近已加载到CRAN上.我一直在玩演示代码并尝试将其嵌入到knitr markdown文档中.不幸的是,当我这样做时,我收到一条错误消息,我无法解释出现了什么问题.

这是错误消息,后面是可重现的示例.请注意,在将代码作为直接R代码运行时,我没有任何问题.只有当它通过knitr运行时才会出现问题.如果mapview元素被注释掉,则不会发生错误.

我已经更新了所有的软件包,问题仍然存在.以下是一些系统细节:

  • Windows 7的
  • R版本3.2.2
  • R Studio版本0.99.486
  • mapview版本1.0.0
  • 针织版1.11
  • pandoc版本1.13.1

pandoc.exe:无法获取C:\ Users\my.name\Documents\R\win-library\3.2\mapview\htmlwidgets\lib\leaflet #default #VML C:\ Users\my.name\Documents\R\win-library\3.2\mapview\htmlwidgets\lib\leaflet:openBinaryFile:不存在(没有这样的文件或目录)错误:pandoc文件转换失败,错误67另外:警告消息:正在运行命令'"C:/ Program Files/RStudio/bin/pandoc/pandoc"+ RTS -K512m -RTS Mapview.utf8.md - to html - from markdown + autolink_bare_uris + ascii_identifiers + tex_math_single_backslash-implicit_figures --output Mapview.html --smart --email-obfuscation none - self-contained --standalone --section-divs --template"C:\ Users\my.name\Documents\R\win-library\3.2\rmarkdown\rmd\h\default.html" - 变量"theme:bootstrap"--include-in-header"C:\ Users\my.name\AppData\Local\Temp\Rtmpw9Mi9D\rmarkdown-str1ee41c515f3f.html"--mathjax --variable"mathjax-url:https:/ /cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML " - no-highlight --variable"h ighlightjs = C:\ Users\my.name\Documents\R\win-library\3.2\rmarkdown\rmd\h\highlight"'has status 67执行暂停

---
title: "Test Mapview"
output: html_document
--- …
Run Code Online (Sandbox Code Playgroud)

r knitr r-mapview

3
推荐指数
1
解决办法
916
查看次数

标签 统计

r ×8

ggplot2 ×2

knitr ×2

rstudio ×2

aggregate-functions ×1

download ×1

excel ×1

plot ×1

r-mapview ×1

reshape2 ×1

unzip ×1

xml ×1