[r] ggplot에서 범례 제목 제거

다음에서 범례 제목을 제거하려고합니다 ggplot2.

df <- data.frame(
  g = rep(letters[1:2], 5),
  x = rnorm(10),
  y = rnorm(10)
)

library(ggplot2)
ggplot(df, aes(x, y, colour=g)) +
  geom_line(stat="identity") +
  theme(legend.position="bottom")

여기에 이미지 설명 입력

나는 이 질문을 보았고 거기에 어떤 해결책도 나를 위해 일하지 않는 것 같습니다. 대부분은 어떻게 optsdeprecated되고 theme대신 사용 하는지에 대한 오류를 제공합니다 . 나는 또한 다양한 버전을 시도했습니다 theme(legend.title=NULL), theme(legend.title=""), theme(legend.title=element_blank), 등 일반적인 오류 메시지는 다음과 같습니다

'opts' is deprecated. Use 'theme' instead. (Deprecated; last used in version 0.9.1)
'theme_blank' is deprecated. Use 'element_blank' instead. (Deprecated; last used in version 0.9.1)

ggplot20.9.3 버전이 출시 된 이후 처음으로 사용 하고 있으며 일부 변경 사항을 탐색하기가 어렵습니다.



답변

거의 완료되었습니다. 추가하기 만하면됩니다. theme(legend.title=element_blank())

ggplot(df, aes(x, y, colour=g)) +
  geom_line(stat="identity") +
  theme(legend.position="bottom") +
  theme(legend.title=element_blank())

R 용 Cookbook의이 페이지에서는 범례를 사용자 지정하는 방법에 대한 자세한 내용을 제공합니다.


답변

이것도 작동하며 범례 제목을 변경하는 방법도 보여줍니다.

ggplot(df, aes(x, y, colour=g)) +
  geom_line(stat="identity") +
  theme(legend.position="bottom") +
  scale_color_discrete(name="")


답변

labs색상을 사용 하고 NULL.

ggplot(df, aes(x, y, colour = g)) +
  geom_line(stat = "identity") +
  theme(legend.position = "bottom") +
  labs(colour = NULL)

여기에 이미지 설명 입력


답변

들어 Error: 'opts' is deprecated. theme()대신 사용하십시오 . (소멸, 마지막 버전 0.9.1에서 사용) ‘나 교체 opts(title = "Boxplot - Candidate's Tweet Scores")와 함께
labs(title = "Boxplot - Candidate's Tweet Scores"). 작동했습니다!


답변

플롯에 하나 이상의 전설이있을 수 있기 때문에, 선택적으로 할 수있는 방법은 빈 공간을 떠나지 않고 제목의 한을 제거하면 설정하는 것입니다 name의 인수 scale_에 기능 NULL, 즉

scale_fill_discrete(name = NULL)

( 다른 스레드에 대한 의견은 @pascal에 대한 찬사 )


답변