Legend as text alongside points for each category and with same collor

纵饮孤独 提交于 2019-12-12 13:56:59

问题


I would like to make scatter plot in R, of variables Y and X over categories Z (separated by colors) but with a special legend. Not a legend box, but for the category names to appear as texts along the points for that category, and the text be the same color as the points.

Is there a way for R to do this automatically?

PS: I know I this could be done "manually" adding "text()" and specifying the location and color of each category

For example, I'm trying to replicate the look of this chart (which I made manually in Stata):

EDIT: after reading the comments bellow, here is the data, and the solution to the problem:

library(ggplot2);library(reshape);library(scales);library(directlabels)
dat <- read.csv("https://dl.dropboxusercontent.com/u/4329509/Fdat_graf.csv")
dat_long <- melt(dat, id="ano")
p <-   qplot(ano,value, data=dat_graf_long, colour=variable)+       scale_y_log10(breaks=c(.1,1,10,100,500,1000),labels = comma) + scale_x_continuous(breaks=seq(from=1960, to=2010, by=10))  + theme_bw()
direct.label(p)

For those interested, the chart if for the sizes of commonly used datasets (household survey (PNAD, ~0.3GB ), CENSUS microdata (~10GB), and a registry of all employment contracts (RAIS, 20GB per year)), against the available memory (RAM) of a decently sized server (baseline is a 96GB RAM server in 2010) growing at Moore's Law rate. It shows how was once thought as "Big Data" is bound to become "small data" due to the advance of Moore's Law.

来源:https://stackoverflow.com/questions/25612656/legend-as-text-alongside-points-for-each-category-and-with-same-collor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!