这里的问题并不完全是如何通过R绘制地图,因为我已经发现这里有一个非常好的例子,而是如何让它工作.实际上,我无法加载库rgdal:
library(rgdal)
Error in library(rgdal) : there is no package called ‘rgdal’
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试手动安装上面的包时,我收到以下错误:
....
configure: error: proj_api.h not found in standard or given locations.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/home/eualin/R/i686-pc-linux-gnu-library/2.15/rgdal’
Warning in install.packages : installation of package ‘/home/eualin/Downloads/rgdal_0.8-5.tar.gz’ had non-zero exit status
Run Code Online (Sandbox Code Playgroud)
欢迎任何投入!
我开始使用的大ggplot2包中的R打印和的第一件事情我问自己之前每个小区是一个"好,我会用qplot还是ggplot?"
据我所知,它qplot提供了更简单的语法,同时ggplot允许最大的功能和灵活性,但你最常用的功能是什么,你是否有一些精确的用例?您是否主要使用qplot并且ggplot仅用于复杂的情节,或者您是否ggplot每次都使用?
感谢您的反馈意见 !
假设我正在开发一个名为的包,foo它希望使用包中的description函数memisc.我不想导入整个memisc命名空间,因为:
memisc覆盖基本aggregate.formula函数,它打破了几件事.例如,example(aggregate) 会悲惨地失败.该软件包包括以下文件:
描述
Package: foo
Version: 0.0
Title: Foo
Imports:
memisc
Collate:
'foo.R'
Run Code Online (Sandbox Code Playgroud)
NAMESPACE
export(bar)
importFrom(memisc,description)
Run Code Online (Sandbox Code Playgroud)
R/foo.R
##' bar function
##'
##' @param x something
##' @return nothing
##' @importFrom memisc description
##' @export
`bar` <- function(x) {
description(x)
}
Run Code Online (Sandbox Code Playgroud)
我认为使用importFrom 不会加载整个memisc命名空间,但只是namespace::description,但事实并非如此.从香草R开始:
R> getS3method("aggregate","formula")
## ... function code ...
## <environment: namespace:stats>
R> library(foo)
R> getS3method("aggregate","formula")
## ... function code …Run Code Online (Sandbox Code Playgroud) 我想知道是否有办法用ggplot2绘制"轮廓文本",例如带有白色小边框的黑色文本,以便在背景(如地图)上轻松阅读.
理想情况下,我想要在Google地图上看到相同类型的标签:

提前感谢任何提示!
我需要在R中将一组命令应用于目录中的所有单个.txt文件(大约300个).
我对R不太熟悉,所以我在网上看到的有关循环的所有帮助都令人困惑,或者当你需要对每个文件应用多个命令时,我无法解决如何应用循环.
我需要应用于目录中的每个文件(系统发育树)的命令(使用R的ape库):
testtree <- read.tree("tree123.txt")
unrooted_tr <- unroot(testtree)
write.tree(unrooted_tr, file="unrootedtree123.txt")
Run Code Online (Sandbox Code Playgroud)
如何应用一个循环,将这些命令应用于每个单独的.txt文件(使用R或在Unix命令行中)?输出(例如unrootedtree123.txt)将需要为每个单独的文件使用不同的名称.
提前谢谢,Dani.
当我尝试回答关于R的Stack Overflow中的一个问题时,我花费了很多时间来尝试重建作为示例给出的数据(除非问题作者已经足够好以提供它们作为R代码).
所以我的问题是,如果有人问一个问题并按以下方式给出他的样本数据框:
a b c
1 11 foo
2 12 bar
3 13 baz
4 14 bar
5 15 foo
Run Code Online (Sandbox Code Playgroud)
您是否有一个提示或功能可以轻松地将其导入R会话,而无需键入整个data.frame()指令?
提前感谢任何暗示!
PS:对不起如果术语"查询"在我的问题标题中不是很好,但似乎你不能在堆栈溢出的问题标题中使用"问题"这个词:-)
我有一个使用此代码创建的数据框:
require(reshape2)
foo <- data.frame( abs( cbind(rnorm(3),rnorm(3, mean=.8),rnorm(3, mean=.9),rnorm(3, mean=1))))
qux <- data.frame( abs( cbind(rnorm(3),rnorm(3, mean=.3),rnorm(3, mean=.4),rnorm(1, mean=2))))
bar <- data.frame( abs( cbind(rnorm(3,mean=.4),rnorm(3, mean=.3),rnorm(3, mean=.9),rnorm(3, mean=1))))
colnames(foo) <- c("w","x","y","z")
colnames(qux) <- c("w","x","y","z")
colnames(bar) <- c("w","x","y","z")
rownames(foo) <- c("n","q","r")
rownames(qux) <- c("n","q","r")
rownames(bar) <- c("n","q","r")
foo <- cbind(ID=rownames(foo),foo)
bar <- cbind(ID=rownames(bar),qux)
qux <- cbind(ID=rownames(bar),qux)
foo$fn <- "foo"
qux$fn <- "qux"
bar$fn <- "bar"
alldf<-rbind(foo,qux,bar)
alldf.m <- melt(alldf)
Run Code Online (Sandbox Code Playgroud)
我想要做的是创建一个facet格式的ggplot线条曲线,所以它创建一个如下图形:

实际图形不包含向上线 - 这只是一个草图,因此线条分离是清晰的.
我当前的代码不起作用:
library(ggplot2)
p <- ggplot(data=alldf.m, aes(x=variable)) …Run Code Online (Sandbox Code Playgroud) 有时在Stack Overflow上,有一个问题与我的系统上没有安装的软件包相关,我不打算稍后再使用.
如果我安装了软件包install.packages(),它将被放入我的一个R安装库中,然后将占用一些存储空间并在每次运行时进行更新update.packages().
有没有办法只为当前的R会话安装包?
假设我有以下内容data.table:
dt <- data.table(id = c(rep(1, 5), rep(2, 4)),
sex = c(rep("H", 5), rep("F", 4)),
fruit = c("apple", "tomato", "apple", "apple", "orange", "apple", "apple", "tomato", "tomato"),
key = "id")
id sex fruit
1: 1 H apple
2: 1 H tomato
3: 1 H apple
4: 1 H apple
5: 1 H orange
6: 2 F apple
7: 2 F apple
8: 2 F tomato
9: 2 F tomato
Run Code Online (Sandbox Code Playgroud)
每一行代表一个人(由它确定id并且sex)吃了a 的事实fruit.我想计算每次fruit被吃掉的次数 …
我需要在以下示例中转义双引号并且R返回:
xx<-"the road is 'rocky all \"the\" way'"
xx
[1] "the road is 'rocky all \"the\" way'"
Run Code Online (Sandbox Code Playgroud)
最后一个字符串应包含单引号和双引号
the road is 'rocky all "the" way'
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?