我正在关注第7-8页的vignette中的示例(在“一些基本示例”下)。
以下是代码:
library(xkcd)
volunteers <- data.frame(year=c(2007:2011),
number=c(56470, 56998, 59686, 61783, 64251))
xrange <- range(volunteers$year)
yrange <- range(volunteers$number)
ratioxy <- diff(xrange) / diff(yrange)
datalines <- data.frame(xbegin=c(2008.3,2010.5),ybegin=c(63000,59600),
xend=c(2008.5,2010.3), yend=c(63400,59000))
mapping <- aes(
x = x, y = y, scale = scale, ratioxy = ratioxy, angleofspine = angleofspine,
anglerighthumerus = anglerighthumerus, anglelefthumerus = anglelefthumerus,
anglerightradius = anglerightradius, angleleftradius = angleleftradius,
anglerightleg = anglerightleg, angleleftleg = angleleftleg,
angleofneck = angleofneck)
dataman <- data.frame( x= c(2008,2010), y=c(63000, 58850),
scale = 1000 ,
ratioxy = ratioxy,
angleofspine = -pi/2 ,
anglerighthumerus = c(-pi/6, -pi/6),
anglelefthumerus = c(-pi/2 - pi/6, -pi/2 - pi/6),
anglerightradius = c(pi/5, -pi/5),
angleleftradius = c(pi/5, -pi/5),
angleleftleg = 3*pi/2 + pi / 12 ,
anglerightleg = 3*pi/2 - pi / 12,
angleofneck = runif(1, 3*pi/2-pi/10, 3*pi/2+pi/10))
p <- ggplot() + geom_smooth(mapping=aes(x=year, y =number),
data =volunteers, method="loess") +
xkcdaxis(xrange,yrange) +
ylab("Volunteers at Caritas Spain") +
xkcdman(mapping, dataman) +
annotate("text", x=2008.7, y = 63700,
label = "We Need\nVolunteers!", family="xkcd" ) +
annotate("text", x=2010.5, y = 60000,
label = "Sure\nI can!", family="xkcd" ) +
xkcdline(aes(xbegin=xbegin,ybegin=ybegin,xend=xend,yend=yend),
datalines, xjitteramount = 0.12)
Warning: Ignoring unknown aesthetics: xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, diameter
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, diameter
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, diameter
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, diameter
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: scale, ratioxy, angleofspine, anglerighthumerus, anglelefthumerus, anglerightradius, angleleftradius, anglerightleg, angleleftleg, angleofneck, xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: xbegin, ybegin, xend, yend
Warning: Ignoring unknown aesthetics: xbegin, ybegin, xend, yend
正如我们所看到的,出现了大量的警告。深入研究各种功能并没有提供太多的见解;我唯一的猜测是ggplot2
不知道如何处理这些不同的美学。为什么会出现这些警告,这是一个问题吗?
会话信息:
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xkcd_0.0.5 extrafont_0.17 ggplot2_2.2.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.9 RColorBrewer_1.1-2 plyr_1.8.4
[4] base64enc_0.1-3 tools_3.3.1 rpart_4.1-10
[7] digest_0.6.12 tibble_1.2 gtable_0.2.0
[10] htmlTable_1.9 checkmate_1.8.2 lattice_0.20-33
[13] Matrix_1.2-6 gridExtra_2.2.1 Rttf2pt1_1.3.4
[16] stringr_1.2.0 cluster_2.0.4 knitr_1.15.1
[19] htmlwidgets_0.8 grid_3.3.1 nnet_7.3-12
[22] data.table_1.10.4 survival_2.41-2 foreign_0.8-66
[25] latticeExtra_0.6-28 Formula_1.2-1 extrafontdb_1.0
[28] magrittr_1.5 Hmisc_4.0-2 scales_0.4.1
[31] backports_1.0.5 htmltools_0.3.5 splines_3.3.1
[34] assertthat_0.1 colorspace_1.3-2 labeling_0.3
[37] stringi_1.1.2 acepack_1.4.1 lazyeval_0.2.0
[40] munsell_0.4.3
答案 0 :(得分:1)
我重新运行了你的代码,它给了一个非常好的结果(我希望这是你所期待的)。
首先,更新所有相关的软件包, ggplot2,extrafont,xkcdcolors,xkcd等
我刚刚为你提供的代码添加了一些额外的库和最后一行,它就像一个魅力,
代码如下:
library(xkcd)
library(xkcdcolors)
library(extrafont)
volunteers <- data.frame(year=c(2007:2011),
number=c(56470, 56998, 59686, 61783, 64251))
xrange <- range(volunteers$year)
yrange <- range(volunteers$number)
ratioxy <- diff(xrange) / diff(yrange)
datalines <- data.frame(xbegin=c(2008.3,2010.5),ybegin=c(63000,59600),
xend=c(2008.5,2010.3), yend=c(63400,59000))
mapping <- aes(
x = x, y = y, scale = scale, ratioxy = ratioxy, angleofspine = angleofspine,
anglerighthumerus = anglerighthumerus, anglelefthumerus = anglelefthumerus,
anglerightradius = anglerightradius, angleleftradius = angleleftradius,
anglerightleg = anglerightleg, angleleftleg = angleleftleg,
angleofneck = angleofneck)
dataman <- data.frame( x= c(2008,2010), y=c(63000, 58850),
scale = 1000 ,
ratioxy = ratioxy,
angleofspine = -pi/2 ,
anglerighthumerus = c(-pi/6, -pi/6),
anglelefthumerus = c(-pi/2 - pi/6, -pi/2 - pi/6),
anglerightradius = c(pi/5, -pi/5),
angleleftradius = c(pi/5, -pi/5),
angleleftleg = 3*pi/2 + pi / 12 ,
anglerightleg = 3*pi/2 - pi / 12,
angleofneck = runif(1, 3*pi/2-pi/10, 3*pi/2+pi/10))
p <- ggplot() + geom_smooth(mapping=aes(x=year, y =number),
data =volunteers, method="loess") +
xkcdaxis(xrange,yrange) +
ylab("Volunteers at Caritas Spain") +
xkcdman(mapping, dataman) +
annotate("text", x=2008.7, y = 63700,
label = "We Need\nVolunteers!", family="xkcd" ) +
annotate("text", x=2010.5, y = 60000,
label = "Sure\nI can!", family="xkcd" ) +
xkcdline(aes(xbegin=xbegin,ybegin=ybegin,xend=xend,yend=yend),
datalines, xjitteramount = 0.12)
p
然而, xkcd-fonts 缺少警告,警告看起来像:
Warning message:In theme_xkcd() : Not xkcd fonts installed! See vignette("xkcd-intro")
。我忽略了它,在最后一行p
之后,我得到了以下输出,
这就是我想你想要的。
要处理警告,请参阅Section 2 | xkcd-vignettes | Journal of Statistical Software | Section 2。
干杯!
答案 1 :(得分:1)
警告是无害的,如果有点烦人的话。要删除它们,需要对xkcdline.R
源进行编辑,以便在传递给geom_path()
之前从映射中删除额外的美学效果。从0.05版本开始,需要对xkcdline.R
进行以下更改:
新的内部功能:
remove_xkcd_mappings <- function(mapping) {
mapping <- mapping[!(names(mapping) %in% c("xbegin",
"xend",
"ybegin",
"yend",
"diameter",
"scale",
"ratioxy",
"angleofspine",
"anglerighthumerus",
"anglelefthumerus",
"anglerightradius",
"angleleftradius",
"anglerightleg",
"angleleftleg",
"angleofneck"))]
}
更改为xkcdline
功能结束:
listofpaths <- lapply(listofinterpolateswithillustrativedata,
function(x, mapping, mask, ...) {
pathmask <- NULL
##print(mapping)
if(mask) {
## Plot a white line widther that the original line
## We must check the color, colour or size
## and change them to white and a greater width
argList<-list(...)
for(i in intersect(c("color","colour"), names(argList)))
argList[i] <- NULL
argList$mapping <- remove_xkcd_mappings(mapping)
argList$data <- x
argList$colour <- "white"
if(is.null(argList$size)==TRUE) argList$size <- 3
if(argList$size <= 3 ) argList$size <- 3
else argList$size <- argList$size *2
##print(argList)
pathmask <- do.call("geom_path",argList)
##pathmask <- geom_path(mapping = mapping, data = x, colour="white",size=8)
}
c(pathmask,
geom_path(mapping = remove_xkcd_mappings(mapping), data = x, ...))
},
mapping = mapping,
mask= mask
## mask = mask,
## ... = ... ggplot2.0 does not like dots
)
listofpaths
我已将xkcd
版本置于github。这可以使用devtools::install_github("NikNakk/xkcd")
安装。
仍有警告与此loess
在此数据集上的使用有关,但这些警告与xkcd
无关。通过绘制以下内容可以看出这一点:
ggplot() + geom_smooth(mapping = aes(x = year, y = number),
data = volunteers, method = "loess")