【问题标题】:Error with textplot in wordcloudwordcloud 中的文本图错误
【发布时间】:2016-04-18 02:29:11
【问题描述】:

当我使用 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
> 

【问题讨论】:

    标签: r graph word-cloud


    【解决方案1】:

    您遇到的错误是由于 textplot 函数使用的语法不正确:

    textplot(object, halign=c("center","left","right"),
         valign=c("center", "top", "bottom"), cex, ... )
    

    在您的示例中,“object”参数以 pca1$li[,1] 形式给出,而“halign”以 pca1$li[,2] 形式给出。

    由于 "halign" 只接受 "center"、"left" 或 "right" 的参数,给 pca$li[,2] 的参数不正确会返回错误消息。

    【讨论】:

    • 谢谢 - 你间接回答了我的问题。我打算在 wordcloud 包中使用 textplot(而不是在 gplots 中)。由于我已经加载了 gplots 和 wordcloud,所以 wordcloud 的公式不起作用。只加载了 wordcloud 包,现在一切都很好!!!
    猜你喜欢
    • 2015-03-14
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    • 2018-05-11
    • 2016-04-25
    • 1970-01-01
    相关资源
    最近更新 更多