【发布时间】:2017-05-24 22:08:41
【问题描述】:
我使用 ggplot2 和 ggrepel 已经有一段时间了,但我的其中一个情节出现了问题(它工作得很好,但突然停止工作,我不知道为什么)。
基本上,我正在使用 ggrepel 和 ggplot2 制作一个 wordcloud,其中包括我数据的每一行的 3 种不同颜色。为此,我使用了 scale_color_manual。有时,数据没有这 3 种颜色,所以这就是我使用限制的原因。但是现在不行了,只有去掉scale_color_manual的代码才可以。
数据
data.df <- read.table(header = TRUE, text =
"row Palabra.Final Frecuencia NPS INDUSTRIA VA IntervaloNPS
49 años 258 8.63 Bancos SI Amarillo
50 atención 1557 8.32 Bancos SI Amarillo
51 atendido 387 8.95 Bancos SI Amarillo
52 bancos 1748 7.70 Bancos SI Amarillo
53 bien 674 9.24 Bancos SI Verde
54 buen 258 9.27 Bancos SI Verde
55 buena 902 9.31 Bancos SI Verde
56 cajeras 219 7.82 Bancos SI Amarillo
57 clientes 1042 7.65 Bancos SI Amarillo
58 cobros 348 6.18 Bancos SI Rojo
59 corriente 241 7.55 Bancos SI Amarillo
61 crédito 956 7.74 Bancos SI Amarillo
62 cuentas 1240 7.87 Bancos SI Amarillo
64 ejecutivo 1471 7.82 Bancos SI Amarillo
66 gente 287 7.81 Bancos SI Amarillo
69 Información 473 8.09 Bancos SI Amarillo
70 interés 556 7.12 Bancos SI Amarillo
71 internet 507 8.47 Bancos SI Amarillo
72 mantención 218 6.85 Bancos SI Rojo
74 nunca 566 8.43 Bancos SI Amarillo
75 pagina 539 8.15 Bancos SI Amarillo
76 plata 295 7.39 Bancos SI Amarillo
77 problema 1475 8.76 Bancos SI Amarillo
78 producto 238 8.29 Bancos SI Amarillo
79 rápida 297 9.08 Bancos SI Verde
80 seguridad 232 9.42 Bancos SI Verde
81 seguro 308 8.44 Bancos SI Amarillo
82 servicio 652 7.60 Bancos SI Amarillo
83 siempre 712 8.97 Bancos SI Amarillo
84 sucursales 343 8.33 Bancos SI Amarillo
85 tarjeta 798 8.16 Bancos SI Amarillo
86 tasas 236 8.31 Bancos SI Amarillo
87 tiempo 255 7.70 Bancos SI Amarillo")
代码
library(ggplot2)
library(ggrepel)
ggplot(data.df) +
aes(x = 1, y = 1, size = Frecuencia, label = Palabra.Final, color=IntervaloNPS) +
geom_text_repel(segment.size = 0, force = 80) +
scale_size(range = c(2, 15), guide = FALSE) + scale_color_manual(name="NPS",values=c("0 - 6"= "red","7 - 8" = "yellow","9 - 10" ="green"),limits = c("0 - 6","7 - 8", "9 - 10")) +
scale_y_continuous(breaks = NULL) +
scale_x_continuous(breaks = NULL) +
labs(x = '', y = '') +
geom_point(size=0) +
guides(colour = guide_legend(override.aes = list(size=3,linetype=0)))
(实际上这段代码给了我geom_point的警告)
我尝试了很多不同的方法,例如:
- 使用这些代码:http://ggplot2.tidyverse.org/reference/scale_manual.html 这些代码运行良好,但我不知道为什么在这种情况下它没有。
- 分离除 ggplot2 和 ggrepel 之外的所有包。
- 关闭和打开 R.
我不知道如何解决这个问题。如果有人可以提供帮助,那就太好了! 谢谢
【问题讨论】: