[R] wrong labels and colors of points in graph/plot

katharina may.katharina at googlemail.com
Thu Jun 4 19:48:29 CEST 2009


Sorry for the problem with NCStats, I used it from this page not realizing
that this is not 'official':
http://www.rforge.net/NCStats/files/

Thank you for helping me with the color issue, I finally know now what has
happened with the
colors of the points my plots.



David Winsemius wrote:
> 
> Was not able to find NCStats on CRAN or BioConductor repositories. You  
> are wasting our (or mine at any rate) time by giving us dead ends.
> 
> You have been bitten by the "factor snake in the grass". Color should  
> be text rather than a factor if you want the desired results.
> 
> See if this is illuminating and eventually helpful:
>  > str(coefficient2)
> 'data.frame':	26 obs. of  11 variables:
>   $ site_no                  : num  29 10 17 18 19 25 9 33 37 41 ...
>   $ intercept                : num  0.603 2.767 3.6 1.86 2.753 ...
>   $ slope                    : num  0.912 0.867 0.841 0.99 0.911 ...
>   $ average_height           : num  90.4 2096.2 990 1950 2184 ...
>   $ average_crown_length     : num  NA 1066 592 645 795 ...
>   $ average_dbh              : num  11.8 271.2 105.1 169.2 220.9 ...
>   $ average_age              : num  NA 80.3 19.3 50.9 68.2 ...
>   $ average_BM_branches      : num  NA 66649 12679 11246 38049 ...
>   $ average_BM_leaves_needles: num  2.28 31051.41 7727.07 9322.6  
> 27112.2 ...
>   $ average_BM_total         : num  36.7 538194.3 62332.9 163137.2  
> 339177.5 ...
>   $ color                    : Factor w/ 4 levels  
> "violet","yellow",..: 1 2 2 2 2 2 1 3 1 1 ...
>  >  as.character(coefficient2$color)
>   [1] "violet" "yellow" "yellow" "yellow" "yellow" "yellow" "violet"  
> "black"  "violet" "violet" "black"
> [12] "yellow" "violet" "yellow" "violet" "violet" "violet" "yellow"  
> "violet" "violet" "black"  "green"
> [23] "green"  "green"  "green"  "green"
>  >  coefficient2$color <- as.character(coefficient2$color)
> 
> Now do your plots....
> 
> -- 
> David
> 
> On Jun 4, 2009, at 12:54 PM, katharina wrote:
> 
>>
>> sorry, the attachment can be found here for download:
>> http://www.wzw.tum.de/waldinventur/fileadmin/coefficient2.RData
>>
>>
>>
>> katharina wrote:
>>>
>>> Hi there,
>>>
>>> I trying to solve this problem for the whole day not going anywhere,
>>> so I  really hope maybe somebody can help
>>> me in this community...
>>> I've got an object coefficient2 which I want to plot in differerent
>>> ways, with colors and labels added to the points,
>>> but somehow there seems to be a problem if a value is NA within the
>>> independent variable, resulting in false labels and false colors for
>>> the points.
>>>
>>> plot(coefficient2$intercept ~ coefficient2$average_height,
>>> main="intercepts ::: height", ylab="intercepts", xlab="average height
>>> per site [cm]", xlim=c(20,3020), ylim=c(-2,5),  
>>> col=coefficient2$color)
>>> highlight(coefficient2$intercept ~ coefficient2$average_height,
>>> lbls=coefficient2$site_no,col="Red", cex = .6)
>>>
>>> plot(coefficient2$intercept ~ coefficient2$average_dbh,
>>> main="intercepts ::: dbh", ylab="intercepts", xlab="average dbh per
>>> site [mm]", xlim=c(-10,360), ylim=c(-2,5),col=coefficient2$color )
>>> highlight(coefficient2$intercept ~ coefficient2$average_dbh,
>>> lbls=coefficient2$site_no,col="Red", cex = .6
>>>
>>>
>>> If I create a temporary object for each plot excluding any NA values
>>> for the x axis variable, somehow all points are displayed and the
>>> labels are correct except for the color (I have e.g. no clue why some
>>> points are red which I do not define at all and no ones are yellow
>>> which I use several times).
>>>
>>> #create temp container for all coefficients with average heights for
>>> plotting
>>> coef_avheight <- coefficient2[which(! 
>>> is.na(coefficient2$average_height)),]
>>> plot(coef_avheight$intercept ~ coef_avheight$average_height,
>>> main="intercepts ::: height", ylab="intercepts", xlab="average height
>>> per site [cm]", xlim=c(20,3020), ylim=c(-2,5),
>>> col=coef_avheight$color)
>>> highlight(coef_avheight$intercept ~ coef_avheight$average_height,
>>> lbls=coef_avheight$site_no,col="Red", cex = .6)
>>>
>>> #create temp container for all coefficients with average dbh for  
>>> plotting
>>> coef_avdbh<- coefficient2[which(!is.na(coefficient2$average_dbh)),]
>>> plot(coef_avdbh$intercept ~ coef_avdbh$average_dbh,  main="intercepts
>>> ::: dbh", ylab="intercepts", xlab="average dbh per site [mm]",
>>> xlim=c(-10,360), ylim=c(-2,5),col=coef_avdbh$color )
>>> highlight(coef_avdbh$intercept ~ coef_avdbh$average_dbh,
>>> lbls=coef_avdbh$site_no,col="Red", cex = .6)
>>>
>>>
>>> Maybe someone can explain me the color issue and the problem with the
>>> NA values which results in a wrong labeling and to few
>>> points being displayed? I'm new to R as you can guess and my code
>>> isn't really elegant but I really cannot get faults within it...
>>>
>>>
>>> Attached you can find the referred R object (coefficient2).
>>> highlight requires library(NCStats)...
>>>
>>> Thank you very, very much,
>>>
>>>                       Katharina
>>>
>>> ______________________________________________
>>> 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.
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/wrong-labels-and-colors-of-points-in-graph-plot-tp23873337p23873849.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
> 
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/wrong-labels-and-colors-of-points-in-graph-plot-tp23873337p23874725.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list