freeazabird
freeazabird

Reputation: 391

How to add automated data labels to line plot?

I've produced a simple line plot using base R and want to add data labels to the point. Any idea how to do this in an automated way? Picture of graph produced here enter image description here

plot(grant$year, grant$grantee, type = "o", xlab = "Year", ylab = "Number of Grantees", pch = 16, col = "dark blue", lwd = 3, cex = 2)

Upvotes: 0

Views: 126

Answers (1)

Neil
Neil

Reputation: 26

I estimated your data from the linked picture. By adding text(grant$year, grant$grantee, labels = grant$grantee, pos = 3) after your plot gives us labels. pos = 3 puts the labels above the data points.

year <- c(2015,2016,2017,2018,2019,2020)
grantee <- c(50,55,51,30,52,83)
grant <- data.frame(year, grantee)
plot(grant$year, grant$grantee, type = "o", xlab = "Year", ylab = "Number of Grantees", pch = 16,  col = "dark blue", lwd = 3, cex = 2)
text(grant$year, grant$grantee, labels = grant$grantee, pos = 3)

Upvotes: 1

Related Questions