簡體   English   中英

將圖例添加到 R 中的多列圖

[英]Adding legend to a multiple column graph in R

我一直在拼命地嘗試在我想要制作的圖表中添加一個圖例,遵循以前問題的許多答案,但直到現在都沒有成功。

誰能向我解釋我必須添加到以下代碼行以獲得圖例(或者也可能解釋為什么它不會自動生成它(在 ELI5 模式下 - 我真的無法掌握 aes() 參數)) ? :-)


ggplot(dfm_hl, aes(stringr::str_wrap(document, 15), group = 1)) +
  geom_point(aes(y = positive), color = "darkred") +
  geom_point(aes(y = negative), color = "steelblue") +
  geom_line(aes(y = positive), color = "darkred") +
  geom_line(aes(y = negative), color = "steelblue") +
  labs(title="Sentiment Across Industries", y="Sentiment (%)", x="Industry") +
  theme(text = element_text(size=8), axis.text.x = element_text(angle = 0, hjust = 0.5))

Dataframe 有問題1 Output 我得到了2

嘿 bud 在控制台中運行所有內容,您應該可以使用:

legend(x = 0, y = -1, legend = c("item1", "item2"), col = c("black", "red"), 
       pch = c(1, 16))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM