在 geom_point 中标记点 [英] Label points in geom_point

查看:43
本文介绍了在 geom_point 中标记点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的数据来自下面列出的互联网来源

The data I'm playing with comes from the internet source listed below

nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv", sep=",")

我想要做的是创建一个 2D 点图,比较该表中的两个指标,每个玩家代表图表上的一个点.我有以下代码:

What I want to do, is create a 2D points graph comparing two metrics from this table, with each player representing a dot on the graph. I have the following code:

nbaplot <- ggplot(nba, aes(x= MIN, y= PTS, colour="green", label=Name)) + 
                  geom_point() 

这给了我以下内容:

我想要的是点旁边的玩家姓名标签.我认为 ggplot 美学中的标签功能会为我做到这一点,但事实并非如此.

What I want is a label of player's name right next to the dots. I thought the label function in ggplot's aesthetics would do this for me, but it didn't.

我还尝试了 text() 函数和 library(calibrate) 中的 textxy() 函数,但它们似乎都无法使用ggplot.

I also tried text() function and the textxy() function from library(calibrate), neither of which appears to work with ggplot.

如何为这些点添加名称标签?

How can I add name labels to these points?

推荐答案

使用 geom_text ,带有 aes 标签.您可以使用 hjust, vjust 来调整文本位置.

Use geom_text , with aes label. You can play with hjust, vjust to adjust text position.

ggplot(nba, aes(x= MIN, y= PTS, colour="green", label=Name))+
  geom_point() +geom_text(aes(label=Name),hjust=0, vjust=0)

  ggplot(nba, aes(x= MIN, y= PTS, colour="green", label=Name))+
  geom_point() +
  geom_text(aes(label=ifelse(PTS>24,as.character(Name),'')),hjust=0,vjust=0)

这篇关于在 geom_point 中标记点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆