Dear all, I was trying to plot the average of different variables at the same time; I used the aggregate function and I obtained correctly the averages I wanted. However when I have tried to plot the data the outlook of the data is a bar rather than by a symbol; even using the "pch" or the "col" arguments, the bar have remained unchanged. Is there a way to modify those bar into symbols or to eliminate them (perhaps drawing them in white) so that I can superimpose the symbols using the "points" function (as I have done in the following example)? best regards Luigi my.data<-structure(list( column_1 = 1:32, column_2 = structure(c( 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8),.Label = c("Unstimulated", "ESAT6", "CFP10", "Rv3615c", "Rv2654", "Rv3879", "Rv3873", "PHA"), class = "factor"), column_3 = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4), .Label = c("bd", "2m", "1m", "0.5m"), class = "factor"), column_4 = c(71.62097178, 2.892223468, 144.8618621, 40.90079262, 37.0516856, 32.78206822, 72.44424152, 1512.516293, 3164.748333, 1092.634557, 28733.20269, 1207.87783, 729.6090973, 151.8706088, 241.2466141, 9600.963594, 682.865522, 5869.375226, 554.8924896, 2982.759858, 7690.028092, 40.37298719, 942.3549279, 3403.679967, 103.9862389, 35.28562613, 321.5985377, 0.274424607, 3352.874906, 93.76421187, 21.3709382, 4193.183281)), .Names = c("row", "stimulation", "type", "copy"), row.names = c(NA, -32L), class = "data.frame") attach(my.data) AVG<-aggregate(copy ~ stimulation , my.data, mean, na.rm = T) plot(AVG, pch=16, col="white") points(AVG) [[alternative HTML version deleted]]
Hi, Try: plot(copy~as.numeric(stimulation),data=AVG,xaxt="n",xlab="stimulation") axis(1,seq(length(AVG$stimulation)),label=AVG$stimulation) #or library(ggplot2) qplot(stimulation,copy,data=AVG) A.K. On Sunday, March 16, 2014 2:28 PM, Luigi Marongiu <marongiu.luigi at gmail.com> wrote: Dear all, I was trying to plot the average of different variables at the same time; I used the aggregate function and I obtained correctly the averages I wanted. However when I have tried to plot the data the outlook of the data is a bar rather than by a symbol; even using the "pch" or the "col" arguments, the bar have remained unchanged. Is there a way to modify those bar into symbols or to eliminate them (perhaps drawing them in white) so that I can superimpose the symbols using the "points" function (as I have done in the following example)? best regards Luigi my.data<-structure(list( column_1 = 1:32, column_2 = structure(c(? ? 1, 2, 3, 4, 5, 6, 7, 8, ? ? ? ? 1, 2, 3, 4, 5, 6, 7, 8, ? ? ? ? 1, 2, 3, 4, 5, 6, 7, 8, ? ? ? ? 1, 2, 3, 4, 5, 6, 7, 8),.Label = c("Unstimulated", "ESAT6", "CFP10", "Rv3615c", "Rv2654", "Rv3879", "Rv3873", "PHA"), class = "factor"), column_3 = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4), .Label = c("bd", "2m", "1m", "0.5m"), class = "factor"), column_4 = c(71.62097178, 2.892223468, 144.8618621, 40.90079262, 37.0516856, 32.78206822, 72.44424152, 1512.516293, 3164.748333, 1092.634557, 28733.20269, 1207.87783, 729.6090973, 151.8706088, 241.2466141, 9600.963594, 682.865522, 5869.375226, 554.8924896, 2982.759858, 7690.028092, 40.37298719, 942.3549279, 3403.679967, 103.9862389, 35.28562613, 321.5985377, 0.274424607, 3352.874906, 93.76421187, 21.3709382, 4193.183281)), .Names = c("row", "stimulation", "type", "copy"), row.names = c(NA, -32L), class = "data.frame") attach(my.data) AVG<-aggregate(copy ~ stimulation? , my.data, mean, na.rm = T) plot(AVG, pch=16, col="white") points(AVG) ??? [[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.
Hi Luigi It always helps to know what your data is str(AVG) 'data.frame': 8 obs. of 2 variables: $ stimulation: Factor w/ 8 levels "Unstimulated",..: 1 2 3 4 5 6 7 8 $ copy : num 1006 1750 7439 1058 2952 ...> AVGstimulation copy 1 Unstimulated 1005.80527 2 ESAT6 1750.04691 3 CFP10 7438.63889 4 Rv3615c 1057.95323 5 Rv2654 2952.39095 6 Rv3879 79.69747 7 Rv3873 319.35418 8 PHA 4677.58578 Now if you wanted the x variable as numeric you could do plot(1:8, AVG$copy) if it is not as simple as that and you have groups with multiple values then this is a starting point library(lattice) xyplot(copy ~ 1:dim(AVG)[1], AVG) Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mackay at northnet.com.au -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Luigi Marongiu Sent: Monday, 17 March 2014 04:27 To: r-help at r-project.org Subject: [R] plot average from aggregated data Dear all, I was trying to plot the average of different variables at the same time; I used the aggregate function and I obtained correctly the averages I wanted. However when I have tried to plot the data the outlook of the data is a bar rather than by a symbol; even using the "pch" or the "col" arguments, the bar have remained unchanged. Is there a way to modify those bar into symbols or to eliminate them (perhaps drawing them in white) so that I can superimpose the symbols using the "points" function (as I have done in the following example)? best regards Luigi my.data<-structure(list( column_1 = 1:32, column_2 = structure(c( 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8),.Label = c("Unstimulated", "ESAT6", "CFP10", "Rv3615c", "Rv2654", "Rv3879", "Rv3873", "PHA"), class = "factor"), column_3 = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4), .Label = c("bd", "2m", "1m", "0.5m"), class = "factor"), column_4 = c(71.62097178, 2.892223468, 144.8618621, 40.90079262, 37.0516856, 32.78206822, 72.44424152, 1512.516293, 3164.748333, 1092.634557, 28733.20269, 1207.87783, 729.6090973, 151.8706088, 241.2466141, 9600.963594, 682.865522, 5869.375226, 554.8924896, 2982.759858, 7690.028092, 40.37298719, 942.3549279, 3403.679967, 103.9862389, 35.28562613, 321.5985377, 0.274424607, 3352.874906, 93.76421187, 21.3709382, 4193.183281)), .Names = c("row", "stimulation", "type", "copy"), row.names = c(NA, -32L), class = "data.frame") attach(my.data) AVG<-aggregate(copy ~ stimulation , my.data, mean, na.rm = T) plot(AVG, pch=16, col="white") points(AVG) [[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.