[R] Plotting question

jim holtman jholtman at gmail.com
Sun Jul 19 00:36:27 CEST 2009


Your data has commas in the numbers causing them to be read in as factors:

> x <- read.table(textConnection("           ID     Cn read_count
+ 1   MJ-2000-79 10,000       6876
+ 2   MJ-2000-80 10,000      23440
+ 3   MJ-2000-87 10,000      18787
+ 4  MJ-2000-100   8000       4775
+ 5   MJ-2000-81   8000       1542
+ 6   MJ-2000-82   8000       1550
+ 7  MJ-2000-101   6000      15322
+ 8   MJ-2000-83   6000       7023
+ 9   MJ-2000-84   6000        834
+ 10 MJ-2000-102   4000       4216
+ 11  MJ-2000-85   4000       1174
+ 12  MJ-2000-86   4000        404
+ 13 MJ-4000-131   1000       1368
+ 14 MJ-4000-132   1000       2219
+ 15 MJ-4000-125    800        413
+ 16 MJ-4000-133    800       2594
+ 17 MJ-4000-127    600       3059
+ 18 MJ-4000-134    600       1561
+ 19 MJ-4000-142    600        848
+ 20 MJ-4000-129    400        182
+ 21 MJ-4000-130    400       1410
+ 22 MJ-4000-135    400       2713
+ 23 MJ-7000-182    100        943
+ 24 MJ-8000-184    100        318
+ 25 MJ-8000-185     80         92
+ 26 MJ-8000-186     80        161
+ 27 MJ-8000-188     60        158
+ 28 MJ-8000-191     60        103
+ 29 MJ-8000-192     40        468
+ 30 MJ-8000-193     40        432"), header=TRUE)
> str(x)  # notice that the column is a factor; comma is not recognizable in numbers
'data.frame':   30 obs. of  3 variables:
 $ ID        : Factor w/ 30 levels "MJ-2000-100",..: 4 5 12 1 6 7 2 8 9 3 ...
 $ Cn        : Factor w/ 12 levels "10,000","100",..: 1 1 1 12 12 12 9 9 9 6 ...
 $ read_count: int  6876 23440 18787 4775 1542 1550 15322 7023 834 4216 ...
> # remove the comma and convert to numeric
> x$Cn <- as.numeric(gsub(",", "", as.character(x$Cn)))
> str(x)
'data.frame':   30 obs. of  3 variables:
 $ ID        : Factor w/ 30 levels "MJ-2000-100",..: 4 5 12 1 6 7 2 8 9 3 ...
 $ Cn        : num  10000 10000 10000 8000 8000 8000 6000 6000 6000 4000 ...
 $ read_count: int  6876 23440 18787 4775 1542 1550 15322 7023 834 4216 ...
> plot(x$Cn, x$read_count)
>
>
>

On Sat, Jul 18, 2009 at 6:18 PM, ANJAN
PURKAYASTHA<anjan.purkayastha at gmail.com> wrote:
> Hi I have a data set that needs to be plotted (see below)
> When I plot it using the simple plot(read_count ~ Cn), I get box plots for
> the read_count numbers plotted according to Cn. The Cn's on the x-axis are
> ordered: 10000, 100, 1000, 40, 400, 4000...
> How do I plot so that Cn is plotted on the x-axis in an ascending order: 40,
> 60, 80, .......10000?
>
> Thanks for your help.
> Anjan
>
>
>            ID     Cn read_count
> 1   MJ-2000-79 10,000       6876
> 2   MJ-2000-80 10,000      23440
> 3   MJ-2000-87 10,000      18787
> 4  MJ-2000-100   8000       4775
> 5   MJ-2000-81   8000       1542
> 6   MJ-2000-82   8000       1550
> 7  MJ-2000-101   6000      15322
> 8   MJ-2000-83   6000       7023
> 9   MJ-2000-84   6000        834
> 10 MJ-2000-102   4000       4216
> 11  MJ-2000-85   4000       1174
> 12  MJ-2000-86   4000        404
> 13 MJ-4000-131   1000       1368
> 14 MJ-4000-132   1000       2219
> 15 MJ-4000-125    800        413
> 16 MJ-4000-133    800       2594
> 17 MJ-4000-127    600       3059
> 18 MJ-4000-134    600       1561
> 19 MJ-4000-142    600        848
> 20 MJ-4000-129    400        182
> 21 MJ-4000-130    400       1410
> 22 MJ-4000-135    400       2713
> 23 MJ-7000-182    100        943
> 24 MJ-8000-184    100        318
> 25 MJ-8000-185     80         92
> 26 MJ-8000-186     80        161
> 27 MJ-8000-188     60        158
> 28 MJ-8000-191     60        103
> 29 MJ-8000-192     40        468
> 30 MJ-8000-193     40        432
>
> --
> =============================
> anjan purkayastha, phd
> bioinformatics analyst
> whitehead institute for biomedical research
> nine cambridge center
> cambridge, ma 02142
>
> purkayas [at] wi [dot] mit [dot] edu
> 703.740.6939
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list