Friday 15 April 2011

graph - Change the symbol of specific data points in line plot, base R -



graph - Change the symbol of specific data points in line plot, base R -

i want alter symbol of particular info points on line graph in base of operations r.

here illustration of plot:

month<-c("2010-08-01", "2010-09-01", "2010-10-01", "2010-12-01", "2011-01-01", "2011-02-01", "2011-03-01", "2011-04-01", "2011-05-01", "2011-06-01", "2011-07-01", "2011-09-01", "2011-11-01", "2012-01-01", "2012-02-01", "2012-03-01", "2012-05-01", "2012-07-01", "2012-08-01") prevalence<-c(10,7.5,5.2,3.5,6.4,2.7,5.8,13.2,4.3,4.7,6.4,4.4,5.2,3.3,1.0,3.1,9.9,33.3,1.0) df<-data.frame(month, prevalence) df$month<-as.date(df$month) plot(df$month, df$prevalence,lwd = 1.8, ylim=c(0,40),pch=16, bty='n', ylab="prevalence (%)", xlab="month",col='black',cex=1,cex.lab=1.0,cex.axis=1.0) len = .07 axis(side = 1, @ = df$month, labels=f, tck=-0.015) axis(side=2, at=c(0,10,20,30,40,50), labels=c("", "", "", "", "", ""), tck=-0.015) lines(df$month, df$prevalence, col='black', lwd=1.8)

the graph produced:

the y-value sec lastly point much higher others, , alter point open circle indicate there 3 samples info point. have several of these line graphs overlay in 1 plot, messy seek indicate way manually overlaying symbol on graph.

you can specify separate symbol every info point. provide array instead of single value pch-option of plot

symbol <- rep(16,nrow(df)) symbol[df$prevalence >30] <- 21 plot(df$month, df$prevalence,lwd = 1.8, ylim=c(0,40),pch=symbol, bty='n', ylab="prevalence (%)", xlab="month",col='black',cex=1,cex.lab=1.0,cex.axis=1.0)

r graph plot

No comments:

Post a Comment