簡體   English   中英

使用 aes(因子)或 position 閃避在 ggplot 中編輯圖例(文本)標簽

[英]Editing legend (text) labels in ggplot with aes(factor) or maybe position dodge

我正在嘗試更改與 colors 相關的圖例標題和標簽。 我嘗試使用這個答案作為指導,但它似乎對圖例文本沒有影響。 我認為是因為我使用了一個因素,還是因為我使用了 position 閃避? 腳本和結果如下:

ggplot(ggplot_survey, aes(factor(hurricanes), fill = factor(bldg_flooding))) +
  geom_bar(position = position_dodge2(width = 0.9, preserve = "single")) +
  facet_wrap(facets = vars(C0_time)) +
  scale_color_discrete(labels=c("No", "Yes", "No Response")) +
  labs(title = "Would frequent flooding (building) prompt you to install WCS?", 
       color = "Response",
       x = "Reported Hurricane Exposure",
       y = "Count"
       )

在此處輸入圖像描述

基本上,我希望圖例上方的文本為“響應”,0 為“否”,1 為“是”,NA 為“無響應”。 關於我哪里出錯的任何建議?

根據@silentdevildoll 的回復:

    ggplot(ggplot_survey, aes(factor(hurricanes), fill = factor(bldg_flooding))) +
  geom_bar(position = position_dodge2(width = 0.9, preserve = "single")) +
  facet_wrap(facets = vars(C0_time)) +
  scale_fill_discrete(labels=c("No", "Yes", "No Response")) +
  labs(title = "Would frequent flooding (building) prompt you to install WCS?", 
       fill = "Response",
       x = "Reported Hurricane Exposure",
       y = "Count"
       )

關鍵是在 scale_color_discrete(現在是 scale_fill_discrete)和 labs() 位中替換顏色。 再次感謝!

暫無
暫無

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

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