我想自动将我的标签包装在ggplot2中.这里写了如何为它编写函数(1),但遗憾的是我不知道labeller=label_wrap在我的代码中放入哪里(2).
(1)由hadley执行的功能
label_wrap <- function(variable, value) {
lapply(strwrap(as.character(value), width=25, simplify=FALSE),
paste, collapse="\n")
}
Run Code Online (Sandbox Code Playgroud)
(2)代码示例
df = data.frame(x = c("label", "long label", "very, very long label"),
y = c(10, 15, 20))
ggplot(df, aes(x, y)) + geom_bar(stat="identity")
Run Code Online (Sandbox Code Playgroud)
我想在这里包装一些较长的标签.
我有一个小问题,我自己无法解决这个问题。
我有一个简单的数据框,我想用ggplot2. 当我使用变量权重作为一个因子时,我会得到 x 轴上的所有值,s。plot 2,但不是当我将它用作整数时,s。情节 1。但是,我想使用geom_smooth,它似乎只在plot 1 中起作用,但在plot 2中不起作用,其中重量是一个因素。
我如何在 中得到一个图表ggplot2,它显示了所有的权重值和geom_smooth函数?
考虑这个示例文件:
require(ggplot2)
x <- get.url(https://dl.dropboxusercontent.com/u/109495328/example.csv)
app_df <- read.csv(x, header=T, sep = ",", quote = "", stringsAsFactors = FALSE, na.strings = "..")
colnames(app_df) <- c("Date", "Weight")
date <- as.Date(strptime(app_df$Date, "%d.%m.%Y"))
weight <- app_df$Weight
df <- na.omit(data.frame(date,weight))
# plot 1 (only few values indicated in x …Run Code Online (Sandbox Code Playgroud) 我在python 3.5.1编写,我是一个编程新手.
我根据python样式指南使用带有pep8和pyflakes插件的gedit来显示样式错误.我不知道是否要遵循风格推荐信.
然而,我有三个反复出现的风格缺陷E501: line too long (80 > 79 characters),E502: the backslash is redundant between brackets并且E128/E127/...: continuation line under-indented for visual indent.截图如下.
我的两个问题是:
E501和随后的风格的错误E502和E127/128?我是R的新手,不知道如何使用ggplot2绘制两个data.frames.我收到以下错误消息:Error: ggplot2 doesn't know how to deal with data of class uneval
如何将我的数据与基础世界地图放在一起?
这是我的代码:
require(Hmisc)
require(mapproj)
require(ggplot2)
require(rgdal)
require(maptools)
require(sp)
require(cshapes)
gpclibPermit()
world <- cshp(date=as.Date("2008-1-1"))
world.points <- fortify(world, region='COWCODE')
p <- ggplot(world.points, aes(long,lat,group=group)) + geom_polygon()
dat <- mdb.get("CLIWOC15_2000.mdb") # you can get the data from here: http://pendientedemigracion.ucm.es/info/cliwoc/cliwoc15.htm
tmp <- dat$CLIWOC15[,c("Lon3","Lat3")]
ggplot(world.points,aes(long,lat,group=group))
+geom_polygon()
+geom_point()
+geom_histogram(tmp,aes(Lon3,Lat3),alpha=0.01,size=1)
+coord_map()+ylim(-90,90)
Run Code Online (Sandbox Code Playgroud) 我想知道在我的伪模型中死亡的所有海龟的数量.我怎样才能做到这一点?我非常感谢这个问题的简单快速运行解决方案,比如count dead turtles.
我在考虑这样的例程(但不知道如何实现它):
if turtle is dead % checking all turtles if dead or alive
set death_count death_count + 1 % set counter
tick % go one step ahead in model
这是我的代码示例(到目前为止没有任何检查):
breed [ humans human ]
humans-own [ age ]
to setup
ca
create-humans(random 100)
[
setxy random-xcor random-ycor
set age (random 51)
]
reset-ticks
end
to death
ask humans [
if floor (ticks mod 1) = 0 [
set age age + 1 ]
if …Run Code Online (Sandbox Code Playgroud) 在这个网站上,达文波特先生发表了一个ggplot2关于以任意数据集为例绘制arima预测的函数,他在这里发表.我可以按照他的例子没有任何错误信息.
现在,当我使用我的数据时,我会以警告结束:
1: In window.default(x, ...) : 'end' value not changed
2: In window.default(x, ...) : 'end' value not changed
Run Code Online (Sandbox Code Playgroud)
我知道当我调用此命令时会发生这种情况,因为我pd <- funggcast(yt, yfor)在数据中指出的数据存在问题end = c(2013).但我不知道如何解决这个问题.
这是我使用的代码:
library(ggplot2)
library(zoo)
library(forecast)
myts <- ts(rnorm(55), start = c(1960), end = c(2013), freq = 1)
funggcast <- function(dn, fcast){
en <- max(time(fcast$mean)) # Extract the max date used in the forecast
# Extract Source and Training Data
ds <- as.data.frame(window(dn, end = en)) …Run Code Online (Sandbox Code Playgroud) 我(我自己是一个程序新手)在archlinux中启动脚本时收到以下错误消息,该脚本由朋友编写:
/usr/bin/psxy: error while loading shared libraries: libgdal.so.1: cannot open shared object file: No such file or directory
/usr/bin/psbasemap: error while loading shared libraries: libgdal.so.1: cannot open shared object file: No such file or directory
/usr/bin/ps2raster: error while loading shared libraries: libgdal.so.1: cannot open shared object file: No such file or directory
/usr/bin/psxy: error while loading shared libraries: libgdal.so.1: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
在脚本中,它使用通用映射工具(GMT).我认为问题是链接器问题并且与之相关gdal.安装的版本是:
gdalinfo --version
GDAL 2.0.0, released 2015/06/14 …Run Code Online (Sandbox Code Playgroud) 有没有办法在批处理模式下使用ggsave?当我说批处理模式时,我的意思是我首先通过ggplot绘制所有绘图,然后将每个绘图保存在特定文件夹中.这是一个被称为的论点
plot=last_plot()
Run Code Online (Sandbox Code Playgroud)
但没有其他选择.还有其他选择,比如plot = all_plot()?
我具有由使用由jason.bryer包李克特李克特规模的ggplot(见).如果你在这里使用原始数据运行代码 ,那么我的extrem标签(在最右边)不再出现在图表中(见下图).我该如何解决?

我使用的代码:
library(ggplot2)
library(likert)
library(gridExtra)
competence_bachelor <- rawdata[, substr(names(rawdata), 1, 4) == "Q002"]
competence_bachelor <- rename(competence_bachelor, c(Q002_01 = "Ability to propose new ideas and new solutions", Q002_02 = "Ability to present in public", Q002_03 = "Ability to use a computer", Q002_04 = "Ability to use the Internet", Q002_05 = "Ability to use statistical programs", Q002_06 = "Ability to write reports", Q002_07 = "Knowledge of economic concepts", Q002_08 = "Knowledge of legal concepts", Q002_09 = "Ability …Run Code Online (Sandbox Code Playgroud) 过了一会儿,我在运行 netlogo 模型时收到一条典型的错误消息:
DISTANCE 期望输入是代理,但得到的是 NOBODY。人类 18 跑步距离时出错
到目前为止,我还无法纠正这个错误。Netlogo 显示了源代码中发生错误的位置:
let dist-nearest-resource distance nearest-resource
Run Code Online (Sandbox Code Playgroud)
我相信知道该消息意味着没有可用的绿色补丁。除了说代理应该继续前进并随机走动之外,我确实知道还要编写什么代码。
下面是我的最小模型,以便您更好地理解。有人知道如何解决这个问题吗?
breed [ humans human ]
humans-own [ energy ]
patches-own [ countdown ]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
ca
create-humans(population)
[
set shape "person"
setxy random-xcor random-ycor
]
ask patches [
set pcolor one-of [green brown]
ifelse pcolor = green
[ set countdown 30 ]
[ set countdown random 30 ]
]
reset-ticks
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go-people
ask humans [ orientation ]
end
to orientation
ifelse …Run Code Online (Sandbox Code Playgroud)