3

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):

enter image description here

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.

LucasMation
  • 2,408
  • 2
  • 22
  • 45
  • 3
    Take a look at the [directlabels](http://cran.r-project.org/web/packages/directlabels/index.html) package. If you want more specific help, post some sample data (see tips [here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)) – MrFlick Sep 01 '14 at 20:52
  • Or use http://ggplot2.org/ which is highly customisable. Examples there if you follow the link – Rusan Kax Sep 01 '14 at 20:55
  • The package `ggplot2` feels quite "automatic" in a way that it handles conditional layouts such as yours very well. If you provide some example data, someone might post an answer to show you the basics of `ggplot`. – SimonG Sep 01 '14 at 21:13
  • It's rather straightforward with the 'text' function. In the absence of an example dataset, I suggest reading the help pages for plot and text. – IRTFM Sep 01 '14 at 21:42
  • Tks to MrFlick, "directables" solved it! Posted the solution in the OP – LucasMation Sep 02 '14 at 13:12

0 Answers0