当我在wordcloud包中使用textplot()函数标记图形中的点(PCA)时,我收到错误。
错误是:Error in match.arg(halign) : 'arg' must be NULL or a character vector
以下是x和y变量:
> pca1$li
Axis1 Axis2
01 -26.3659354 18.0330276
02 -19.3576309 -18.9132485
03 -27.2273522 3.3373583
04 -23.0849100 0.9764428
05 8.1548417 29.4034493
06 14.9676626 -8.4668479
07 -9.2283936 4.5088119
08 17.9377761 -11.3030900
09 -0.8272139 2.3342824
10 30.3111878 18.8577228
11 2.0019239 -6.2150041
12 22.2964319 34.6544348
13 25.4172737 -39.6409997
14 4.4278974 -5.5672158
15 4.2769304 -11.4208116
16 19.2807143 -7.9307193
17 5.1918409 -5.2005851
18 -17.6999115 -26.7897873
19 -15.5909519 6.0809629
20 -3.6095312 1.2653160
21 -12.7500774 8.5864060
22 1.4774272 13.4100946
文本(我在这里称之为标签)应该是一个字符向量,我确定:
> labels
[1] "Vipond Park" "Little Joe" "Napa Sunset" "Deadline" "Deschutes" "Gifford Pinchot"
[7] "Mount Hood" "Okanogan" "Warm Springs" "Colville" "Wenatchee" "Olympic"
[13] "Smithers" "Mount Stevens" "Jesmond" "McBridePeak" "Cataract" "Prairie Bluff"
[19] "Tom Beal" "Humboldt" "Warner" "Goosenest"
> class(labels)
[1] "character"
以下是绘制细节(我添加了超过必要的信息,因为我有时会绘制更多数据点):
> myPch <- c(18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18)
>
> myCol <- transp(c("blue","red","darkgreen","black","purple","blue","red","darkgreen","black","purple",
+ "blue","red","darkgreen","black","purple", "blue","red","darkgreen","black","purple", "blue","red",
+ "darkgreen","black","purple", "blue","red","darkgreen","black","purple", "blue","red","darkgreen",
+ "black","purple", "blue","red","darkgreen","black","purple","blue","red","darkgreen","black","purple",
+ "blue","red","darkgreen","black","purple","blue","red","darkgreen","black","purple", "blue","red",
+ "darkgreen","black","purple","blue","red","darkgreen","black","purple"),1)
>
>
>
我绘制数据:
> plot(pca1$li, col=myCol, cex=3, pch=myPch)
> abline(h=0,v=0,col="grey",lty=2)
然后我将标签添加到图中,但我得到以下错误。
> textplot(pca1$li[,1], pca1$li[,2], words = labels, cex=1.4, new=FALSE)
Error in match.arg(halign) : 'arg' must be NULL or a character vector
>
答案 0 :(得分:1)
您获得的错误是由于textplot函数使用的语法不正确:
textplot(object, halign=c("center","left","right"),
valign=c("center", "top", "bottom"), cex, ... )
在你的例子中,&#34;对象&#34;参数以pca1 $ li [,1]给出,而&#34; halign&#34;给出为pca1 $ li [,2]。
因为&#34; halign&#34;只接受&#34; center&#34;,&#34; left&#34;或&#34;对&#34;,给出pca $ li [,2]的错误参数将返回错误消息。