小编Agu*_*cho的帖子

如何在R中创建具有不同数字的字符串序列

我只是想不通如何创建一个矢量,其中字符串是常量但数字不是.例如:

c("raster[1]","raster[2]","raster[3]")
Run Code Online (Sandbox Code Playgroud)

我想使用类似的东西seq(raster[1],raster[99], by=1),但这不起作用.

提前致谢.

r sequence

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

控制ggplot2中水平线的颜色

任何人都可以告诉我这个脚本出了什么问题?我需要2条水平,黑色,虚线,但我有两个红色连续.尽管使用了theme_bw,我也无法将绘图边距的颜色更改为黑色,并且根据需要,框图的填充也不是灰色.

  dat1 <- data.frame (xvar = rep(c("A", "B"), each=10),

                yvar = 1:20 + rnorm(20,sd=3))

  ggplot(dat1, aes(x=xvar, y=yvar)) +
  theme_bw()+
  geom_boxplot(fill=grey)+
  geom_hline(aes(yintercept=40, color="black", linetype="dashed"))+
  geom_hline(aes(yintercept=33.84, color="black", linetype="dashed"))+  
  scale_x_discrete(name="") +
  scale_y_continuous(name="temperature (°C)")+
  opts(
    panel.grid.major = theme_line(size = 0.5, colour = NA),
    panel.background = theme_rect(colour = NA),   
    axis.title.y = theme_text(angle=90,face="bold", colour="black", size=14),
    axis.text.y  = theme_text(face="bold",angle=0, size=14,colour="black"),
    axis.title.x = theme_text(face="bold", colour="black", size=14),
    axis.text.x  = theme_text( size=14,vjust=1.2, colour=NA))
Run Code Online (Sandbox Code Playgroud)

非常感谢!

r ggplot2

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

在R中以粗体标识网络链接

以下脚本允许我访问具有多个具有相似名称的链接的网站.我想只得到其中一个,因为它在网站上以粗体显示,可以与其他人区别开来.但是,我找不到在列表中选择粗体链接的方法.

有人会对此有所了解吗?提前致谢!

library(httr)
library(rvest)
sp="Alnus japonica"

res <- httr::POST(url ="http://apps.kew.org/wcsp/advsearch.do", 
              body = list(page ="advancedSearch", 
                          AttachmentExist ="", 
                          family ="", 
                          placeOfPub ="", 
                          genus = unlist(strsplit(as.character(sp), split="         "))[1], 
                          yearPublished ="", 
                          species = unlist(strsplit(as.character(sp), split="    "))[2], 
                          author ="", 
                          infraRank ="", 
                          infraEpithet ="", 
                          selectedLevel ="cont"), 
              encode ="form") 
pg <- content(res, as="parsed") 
lnks <- html_attr(html_nodes(pg,"a"),"href")
#how get the url of the link wth accepted name (in bold)?
res2 <- try(GET(sprintf("http://apps.kew.org%s", lnks[grep("id=",lnks)]      [1])),silent=T)
#this gets a link but often fails to get the bold one
Run Code Online (Sandbox Code Playgroud)

html r httr rvest

8
推荐指数
2
解决办法
256
查看次数

ggplot2 initFields出错

函数ggplotfrom包ggplot2给出以下错误:

Error in initFields(scales = scales) : 
cannot find function "initRefFields"
Run Code Online (Sandbox Code Playgroud)

通过其他列表,发现更新ggplot2或R到v.14.2将使它工作,但我做了两个,但仍然无法正常工作.任何提示?有会议信息:谢谢!

> sessionInfo()
R version 2.14.2 (2012-02-29)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Spanish_Spain.1252  LC_CTYPE=Spanish_Spain.1252            LC_MONETARY=Spanish_Spain.1252
[4] LC_NUMERIC=C                   LC_TIME=Spanish_Spain.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plyr_1.7.1    ggplot2_0.9.0

loaded via a namespace (and not attached):
[1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2       grid_2.14.0            MASS_7.3-16       
[6] memoise_0.1        munsell_0.3        proto_0.3-9.2      RColorBrewer_1.0-5    reshape2_1.2.1    
[11] scales_0.2.0       stringr_0.6        tools_2.14.0 
Run Code Online (Sandbox Code Playgroud)

r ggplot2

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

在原始拟合数据上绘制非线性混合模型

我试图通过拟合非线性混合模型来绘制合成曲线.它应该像正常分布的曲线,但向右倾斜.我在这里和这里都遵循了以前的链接,但是当我使用我的数据时,我无法在不同的困难中实现它(见下文).

这是数据集 和代码

s=read.csv("GRVMAX tadpoles.csv") 
t=s[s$SPP== levels(s$SPP)[1],]
head(t)
vmax=t[t$PERFOR=="VMAX",]
colnames(vmax)[6]="vmax"
vmax$TEM=as.numeric(as.character(vmax$TEM));
require(lme4)
start =c(TEM=25)
is.numeric(start)
nm1 <- nlmer ( vmax ~ deriv(TEM)~TEM|INDIVIDUO,nlpars=start, nAGQ  =0,data= vmax)# this gives an error suggesting nlpars is not numeric, despite start is numeric...:~/
Run Code Online (Sandbox Code Playgroud)

之后,我想在原始数据上绘制曲线

 with(vmax,plot(vmax ~ (TEM)))
 x=vmax$TEM
 lines(x, predict(nm1, newdata = data.frame(TEM = x, INDIVIDUO = "ACI5")))
Run Code Online (Sandbox Code Playgroud)

任何提示?

提前致谢

r curve-fitting lme4

5
推荐指数
0
解决办法
326
查看次数

abline 不尊重 R 中的截距

以下代码显示了 abline 的奇怪行为:绘制的线未达到指定的截距。我使用的是 Rstudio 版本 0.98.976。有什么提示可以避免这个问题吗?

x=seq(1,10)
y=seq(1,10)
m=lm(y~x)
summary(m)
plot(x,y)
abline(1.123e-15, 1.000e+00)
abline(2, 1.000e+00)
abline(3, 1.000e+00)
abline(4, 1.000e+00)
Run Code Online (Sandbox Code Playgroud)

提前致谢,

在此输入图像描述

plot r

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

标签 统计

r ×6

ggplot2 ×2

curve-fitting ×1

html ×1

httr ×1

lme4 ×1

plot ×1

rvest ×1

sequence ×1