[R] plot with different symbols and colors according to the factor levels

Clint Bowman clint at ecy.wa.gov
Tue Aug 30 19:35:03 CEST 2016


Hanna,

lili<-read.table("lili.txt",header=T)  # don't forget to label the row 
number if it's in your data

with(lili,plot(y,conc,pch=sample,col=sample))

Clint


Clint Bowman			INTERNET:	clint at ecy.wa.gov
Air Quality Modeler		INTERNET:	clint at math.utah.edu
Department of Ecology		VOICE:		(360) 407-6815
PO Box 47600			FAX:		(360) 407-7534
Olympia, WA 98504-7600

         USPS:           PO Box 47600, Olympia, WA 98504-7600
         Parcels:        300 Desmond Drive, Lacey, WA 98503-1274

On Tue, 30 Aug 2016, li li wrote:

> Hi all,
> I have the following data. I want to plot the data (y ~ conc)
> with different symbols and colors corresponding to different levels of the
> factor sample.
> I could create a column with color and pch and then do the plot, but I am
> sure there are much better ways.
> Can anyone make suggestions?
>  Hanna
>
>
>
>   y         conc sample
> 1  33 20.000000000      1
> 2  33  5.000000000      1
> 3  35  1.250000000      1
> 4  43  0.312500000      1
> 5  58  0.078125000      1
> 6  54  0.019531250      1
> 7  57  0.004882812      1
> 8  57  0.001220703      1
> 9  32 20.000000000      1
> 10 32  5.000000000      1
> 11 34  1.250000000      1
> 12 52  0.312500000      1
> 13 57  0.078125000      1
> 14 58  0.019531250      1
> 15 59  0.004882812      1
> 16 50  0.001220703      1
> 17 34 20.000000000      2
> 18 34  5.000000000      2
> 19 38  1.250000000      2
> 20 53  0.312500000      2
> 21 57  0.078125000      2
> 22 57  0.019531250      2
> 23 57  0.004882812      2
> 24 52  0.001220703      2
> 25 34 20.000000000      2
> 26 33  5.000000000      2
> 27 36  1.250000000      2
> 28 48  0.312500000      2
> 29 58  0.078125000      2
> 30 57  0.019531250      2
> 31 58  0.004882812      2
> 32 53  0.001220703      2
> 33 34 20.000000000      2
> 34 35  5.000000000      2
> 35 37  1.250000000      2
> 36 49  0.312500000      2
> 37 55  0.078125000      2
> 38 59  0.019531250      2
> 39 57  0.004882812      2
> 40 54  0.001220703      2
> 41 36 20.000000000      3
> 42 33  5.000000000      3
> 43 36  1.250000000      3
> 44 51  0.312500000      3
> 45 57  0.078125000      3
> 46 57  0.019531250      3
> 47 59  0.004882812      3
> 48 56  0.001220703      3
> 49 33 20.000000000      3
> 50 32  5.000000000      3
> 51 35  1.250000000      3
> 52 47  0.312500000      3
> 53 57  0.078125000      3
> 54 56  0.019531250      3
> 55 57  0.004882812      3
> 56 53  0.001220703      3
> 57 33 20.000000000      3
> 58 34  5.000000000      3
> 59 38  1.250000000      3
> 60 52  0.312500000      3
> 61 56  0.078125000      3
> 62 61  0.019531250      3
> 63 56  0.004882812      3
> 64 55  0.001220703      3
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



More information about the R-help mailing list