The results from each glass type can be identified by the colour, the marker shape and the line type, making it colourblind-friendly and also suitable to be printed in gray-scale. The plot shows the means, the standard deviation and the compact letter display for each treatment. Here we can use filter function to create a new dataframe from gapminder data. And then create a new dataframe containing only the data points we need to highlight. The way to do it is, we first make the scatter plot normally as we did before. This scatterplot is suitable for any presentation and also for written reports. Let us highlight the outlier data points in red using ggplot2. # coloured scatterplot ggplot(data_summary, aes(Temp, mean, color = Glass)) + geom_point( aes( shape = Glass), position= position_dodge( width= 5), alpha= 0.4, size = 3) + geom_line( aes( linetype = Glass), position= position_dodge( width= 5)) + geom_errorbar( aes( ymin=mean -sd, ymax=mean +sd), position= position_dodge( width= 5), width = 5, show.legend = FALSE) + labs( x= "Temperature (˚C)", y= "Light Output") + theme_bw() + theme( = element_blank(), = element_blank()) + theme( legend.position = c( 0.1, 0.7)) + geom_text( aes( label=Tukey), size = 3, position = position_dodge( width= 5), vjust= 1.5, show.legend = FALSE) + scale_x_continuous( breaks= c( 100, 125, 150)) + scale_y_continuous( limits= c( 450, 1450), breaks= seq( 500, 1400, 300)) + scale_color_brewer( palette = "Dark2") If you prefer a video-tutorial, you can watch the tutorial Publication-Quality Scatterplots for Two Factors with ggplot – Two-Way ANOVA with R – tutorial 4 at my YouTube channel. An example using the mpg data set: p <- ggplot(mpg, aes(cty, hwy, color factor(cyl))) p + geompoint(aes(size drv)). You can download the csv file with the summarised data or you can follow the Two-Way ANOVA in R – Step-by-Step Tutorial to build it. To build the scatterplots, we are going to use the summarised data, with the mean, the standard deviation and the letters indicating significant differences by Tukey’s test (compact letter display). The code appears to be, cylfactor<-factor (mtcarscyl) ggplot (mtcars, aes (xmpg, ywt, shapecylfactor))+geompoint () color, as the shape before it, can now be used to represent the third variable. The data 1 presents the results of an experiment conducted to study the influence of the operating temperature (100˚C, 125˚C and 150˚C) and three faceplate glass types (A, B and C) in the light output of an oscilloscope tube. To produce the scatter plot, we must first create a factor from the cylinder variable and then use the ggplot function. In this tutorial we are going to see how to build a high-quality scatterplot for two explanatory variables. Improving the visualisation of the shapes.Customising the x and y limits and axis breaks.Customising the theme and legend position.Avoiding the overlay of the data (position dodge).Using colours and shapes to split the results.
0 Comments
Leave a Reply. |