简体   繁体   English

ggplot2 中的 geom_text 和标题问题

[英]Problem with geom_text and caption in ggplot2

I'm creating a graphic using ggplot2 and I am having difficulty with the subtitle when I use the geom_text function because it is "a" instead of just the colored ball.我正在使用 ggplot2 创建一个图形,当我使用 geom_text 函数时,我在使用副标题时遇到了困难,因为它是“a”,而不仅仅是彩色球。 Here's an example这是一个例子

  head(iris,3)
  kIris <- 3
  iris.kMeans <- kmeans(iris[,1:4], kIris, nstart=20)
  IrisAgrupado <- data.frame(iris, cluster=factor(iris.kMeans$cluster))
  ggplot(IrisAgrupado, aes(x=Petal.Width,y=Sepal.Width,color=cluster, label=Species)) +
  geom_point(color="white")+
  geom_text()

How is the final result of the graph the problem is in the "a" of the caption图的最终结果如何问题在标题的“a”

library(ggplot)
library(ggrepel)

dataframe:数据框:

  kIris <- 3
  iris.kMeans <- kmeans(iris[,1:4], kIris, nstart=20)
  IrisAgrupado <- data.frame(iris, cluster=factor(iris.kMeans$cluster))

plot code:情节代码:

ggplot(IrisAgrupado, aes(x=Petal.Width,y=Sepal.Width,color= Species)) + geom_point(aes(colour = Species))+ scale_color_manual(values = c("red", "blue", "yellow")) + geom_text_repel(show.legend = FALSE, aes(label = Species))

Why this works: show.legend = FALSE removes the 'a' values.为什么会这样: show.legend = FALSE删除 'a' 值。 Then you can perform the aesthetics.然后你可以执行美学。

output:输出: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM