简体   繁体   中英

How to add labels to a scatter plot in ggplot2

I am learning R and using ggplot2. I have tried this answer to solve my question but the labels don't appear, only numbers : how to add labels to a plot

I have three columns: One is called "Departamento" (that means the name of the state in my country), the second one is "Muertes.x.100.000" (that refer to deaths in population caused by cancer per every 100.000 inhabitants) and the third one is "Ingreso.Per.cápita.2.011" (that is the GDP per person in each state).

I got a correlation between number of deaths and gdp per person in 14 states but I want that each point in the graphic appear with the name of the state. My code is:

  ggplot(data=Top7DptosCancervsIngPercapita,aes(x=Ingreso.Per.cápita.2.011, y=Muertes.x.100.000))
  +geom_point(shape=1)
   +geom_smooth(method = lm,se=FALSE)
     +ggtitle("Los 7 Dptos con más y con menos muertes por cancer por 100.000 habitantes del 2.006 al 2.011 y su relación con el Ingreso Per cápita en 2.011")
ggplot(data=Top7DptosCancervsIngPercapita,aes(x=Ingreso.Per.cápita.2.011, y=Muertes.x.100.000)) +
geom_point(shape=1) + geom_smooth(method = lm,se=FALSE)+
ggtitle("Los 7 Dptos con más y con menos muertes por cancer por 100.000 habitantes del 2.006 al 2.011 y su relación con el Ingreso Per cápita en 2.011")+
geom_text(aes(x=Ingreso.Per.cápita.2.011, y=Muertes.x.100.000,label=Departamento))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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