ggplot2不像我想的那样工作

时间:2016-03-16 03:20:22

标签: r plot ggplot2 word-cloud

我尝试使用ggplot2

绘制此视觉效果
ggplot(Trump_df, aes(x=freq.dif, y=Spacing)) +
  geom_text(aes(size=TrumpT.txt, label=row.names(Trump_df),
                colour=freq.dif), alpha=0.7, family="Arial") +
  geom_text(data=Kasich_df, aes(x=freq.dif, y=Spacing,
                                label=row.names(Kasich_df), size=KasichT.txt, color=freq.dif),
            alpha=0.7, family="Arial") +
  geom_text(data=both_df, aes(x=freq.dif, y=Spacing,
                              label=row.names(both_df), size=TrumpT.txt, color=freq.dif),
            alpha=0.7, family="Arial") +
  scale_size(range=c(3,11)) +
  scale_colour_gradient(low="red3", high="blue3", guide="none") +
  scale_x_continuous(breaks=c(min(Kasich_df$freq.dif), 0, max(Trump_df$freq.dif)), 
                     labels=c("Twitted More by Kasich","Twitted Equally","Twitted More by Trump")) +
  scale_y_continuous(breaks=c(0), labels=c("")) +
  labs(title="Conway's Word Cloud, Tweets (Trump -vs- Kasich)", x="", y="", size="Word Frequency") +
  theme_bw() +
  theme(panel.grid.major.y = element_line(),
        panel.grid.minor.x = element_line(),
        plot.title = element_text(family="Arial", size=18)

但是获得一个堆积轴标签的情节: ggplot2 word cloud

以下是我的数据框:

dput(DF)

>dput(df)
structure(list(TrumpT.txt = c(25, 34, 8, 3, 11, 4, 3, 4, 4, 16, 
   4, 8, 21, 16, 3, 21, 3, 10, 9, 11, 4, 6, 3, 4, 3, 6, 4, 3, 5, 
   55), KasichT.txt = c(6, 5, 3, 4, 3, 4, 6, 3, 4, 7, 29, 3, 3, 
   5, 4, 4, 3, 6, 22, 3, 3, 4, 3, 3, 3, 6, 5, 4, 6, 4), freq.dif = c(19, 
   29, 5, -1, 8, 0, -3, 1, 0, 9, -25, 5, 18, 11, -1, 17, 0, 4, -13, 
   8, 1, 2, 0, 1, 0, 0, -1, -1, -1, 51)), .Names = c("TrumpT.txt", 
   "KasichT.txt", "freq.dif"), row.names = c("america", "amp", "back", 
   "best", "can", "candidate", "check", "day", "done", "gopdebate", 
   "john", "join", "just", "make", "nation", "new", "next", "now", 
   "ohio", "one", "see", "state", "talk", "tax", "thanks", "time", 
   "today", "voting", "watch", "will"), class = "data.frame")

dput(DF $ freq.dif)

>dput(df$freq.dif)
c(19, 29, 5, -1, 8, 0, -3, 1, 0, 9, -25, 5, 18, 11, -1, 17, 0, 
  4, -13, 8, 1, 2, 0, 1, 0, 0, -1, -1, -1, 51)

dput(Trump_df)

>dput(Trump_df)
structure(list(TrumpT.txt = c(3, 3, 4, 3, 9, 4, 3, 5), KasichT.txt = c(4, 
  6, 29, 4, 22, 5, 4, 6), freq.dif = c(-1, -3, -25, -1, -13, -1, 
  -1, -1), Spacing = c(-0.4, 0.0249155652709305, -0.184168514423072, 
  -0.2, 0.0361329583451152, 0, 0.2, 0.4)), .Names = c("TrumpT.txt", 
  "KasichT.txt", "freq.dif", "Spacing"), row.names = c("best", 
  "check", "john", "nation", "ohio", "today", "voting", "watch"
  ), class = "data.frame")

dput(Kasich_df)

>dput(Kasich_df)
structure(list(TrumpT.txt = c(25, 34, 8, 11, 4, 16, 8, 21, 16, 
  21, 10, 11, 4, 6, 4, 55), KasichT.txt = c(6, 5, 3, 3, 3, 7, 3, 
  3, 5, 4, 6, 3, 3, 4, 3, 4), freq.dif = c(19, 29, 5, 8, 1, 9, 
  5, 18, 11, 17, 4, 8, 1, 2, 1, 51), Spacing = c(-0.171893353201449, 
  0.113299035839736, -0.5, -0.5, -0.333333333333333, 0.0629540653899312, 
  0.5, -0.161544232908636, 0.166435130592436, 0.193869082257152, 
  0.0795861765742302, 0.5, 0, -0.139369543548673, 0.333333333333333, 
  0.117351376824081)), .Names = c("TrumpT.txt", "KasichT.txt", 
  "freq.dif", "Spacing"), row.names = c("america", "amp", "back", 
  "can", "day", "gopdebate", "join", "just", "make", "new", "now", 
  "one", "see", "state", "tax", "will"), class = "data.frame")

dput(both_df)

>dput(both_df)
structure(list(TrumpT.txt = c(4, 4, 3, 3, 3, 6), KasichT.txt = c(4, 
  4, 3, 3, 3, 6), freq.dif = c(0, 0, 0, 0, 0, 0), Spacing = c(-0.833333333333333, 
  -0.5, -0.166666666666667, 0.166666666666667, 0.5, 0.833333333333333)), .Names = c("TrumpT.txt", "KasichT.txt", "freq.dif", "Spacing"), 
  row.names = c("candidate", "done", "next", "talk", "thanks", 
  "time"), class = "data.frame")

我想在最左边的“卡西奇转弯”,中间的“Twitted Equally”和最右边的“Twitted More by Trump”。我已经尝试搞乱了规模,但我正在做的事似乎不起作用。我很感激任何帮助。

0 个答案:

没有答案
相关问题