extracting and labeling subsets of data

104 views
Skip to first unread message

Ace

unread,
Mar 26, 2012, 12:41:03 AM3/26/12
to ggplot2
I have a datafile. I also have several other datafiles consisting of
subsets of the first datafile.

example

Datafile A consists of several rows of
Label, Control (X), Tacky (Y)

Datafile B (a subset) consists of
Label

Datafile C (a subset) consists of
Label

I need a way to use Datafiles B and C to extract only matching entries
from Datafile A and graph them as a scatterplot with different colors
for different subsets.


valuefile <- read.csv(file.choose())
valuefileB<-read.csv(file.choose())
valuefileC<-read.csv(file.choose())
library(ggplot2)
library(grid)
df = data.frame(Control =valuefile$value_Control, tacky=valuefile
$value_tacky, valuelab=valuefile$labelcol)


plot1<-ggplot(data=df, aes(x=Control, y=tacky, colour=subset )) +
geom_point() + geom_text(size=2,aes(label=valuelab)) +
geom_smooth(method="lm")






If need be I can alter the subset files manually to make a potential
solution easier such as maybe adding a subset value column to each
subset file.

thanks

Sam Albers

unread,
Mar 26, 2012, 1:29:25 AM3/26/12
to Ace, ggplot2
On Sun, Mar 25, 2012 at 9:41 PM, Ace <nko...@gmail.com> wrote:
> I have a datafile. I also have several other datafiles consisting of
> subsets of the first datafile.
>
> example
>
> Datafile A consists of several  rows of
> Label, Control (X), Tacky (Y)
>
> Datafile B (a subset) consists of
> Label
>
> Datafile C (a subset) consists of
> Label
>
> I need a way to use Datafiles B and C to extract only matching entries
> from Datafile A and graph them as a scatterplot with different colors
> for different subsets.
>
>
> valuefile <- read.csv(file.choose())
> valuefileB<-read.csv(file.choose())
> valuefileC<-read.csv(file.choose())

More a general R problem. See ?merge

Bmerge <- merge(valuefile, valuefileB, by="Label")

> library(ggplot2)
> library(grid)

I'm confused as to why you've made another dataframe here. See
?colnames if you are just trying to change the names.

> df = data.frame(Control =valuefile$value_Control, tacky=valuefile
> $value_tacky, valuelab=valuefile$labelcol)
>
>

Is this about right?

ggplot(valuefile, aes(x=Control, y=Tacky)) +
geom_point(alpha=0.4) +
geom_point(data=Bmerge, aes(x=Control, y=Tacky), col='red')

There are undoubtedly more elegant ways of doing this but this should
work if I understand your problem.

HTH,

Sam

> plot1<-ggplot(data=df, aes(x=Control, y=tacky, colour=subset )) +
> geom_point() + geom_text(size=2,aes(label=valuelab)) +
> geom_smooth(method="lm")
>
>
>
>
>
>
> If need be I can alter the subset files manually to make a potential
> solution easier such as maybe adding a subset value column to each
> subset file.
>
> thanks
>

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Reply all
Reply to author
Forward
0 new messages