如何更改GGPLOT GEOM_BAR和Legend Title中的条名?
我有一个数据框架:
id = c("A","B","C","D","E")
C1 = c(T,F,T,F,T)
DAT = tibble(id,C1);DAT
ggplot(DAT,aes(C1,color="lightblue"))+ geom_bar(aes(color="black",fill = "red"))
我想创建一个这样的条形图:
但我想将the更改为“ ok”,false forse fors fors“ nock'右边的传奇不是标题,而不是颜色,而是“检查”。我该如何在R中进行?
可选的
如果我与NA有一行,该如何改变? 例如:
id = c("A","B","C","D","E")
C1 = c(T,F,NA,F,T)
DAT = tibble(id,C1);DAT
I have a data frame :
id = c("A","B","C","D","E")
C1 = c(T,F,T,F,T)
DAT = tibble(id,C1);DAT
ggplot(DAT,aes(C1,color="lightblue"))+ geom_bar(aes(color="black",fill = "red"))
I want to create a bar chart like this one :
But I want to change the true to "ok" and false to "not ok" and also this renaming to appear in the legend at the right with title not colour but "Check". How can I do it in R?
Optional
If I had a row with NA how I could change that ?
For example:
id = c("A","B","C","D","E")
C1 = c(T,F,NA,F,T)
DAT = tibble(id,C1);DAT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
像这样?
由 reprex软件包(v2.0.1)
Like this?
Created on 2022-06-14 by the reprex package (v2.0.1)
要在传说中出现变量,请避免修复颜色,例如
fill =“ LightBlue”
,而是使用所需的变量,例如fill = c1
To have variables appear in your legends, avoid fixing the colour, e.g.
fill = "lightblue"
, instead use the variable you want, e.g.fill = C1
代替
if_else
您可以使用case_when
允许矢量化多个if_else()
语句,例如In place of
if_else
you can usecase_when
which allows to vectorise multipleif_else()
statements like请参阅此答案:
See this answer: