Skip to main content

Posts

Showing posts with the label ggplot2

ggplot2 and lattice

GGPLOT2 Package It is a graphic package implemented in R, it allows to make graphs in a very flexible way since it contains many different commands to perform specific functions when creating and / or manipulating graphs.  In addition, this graphic package has an underlying grammar in layers , so that it is composed of components. These independent components can be combined in different ways to make or modify the chart. Each graph is made from a few equal components: data, visual marks representing data points (geoms), and a coordinate system. The necessary variables for the ggplot command are the data to be used in data frame format and know which variables we will use as x and y: ggplot (df, aes (x, y, )) You can add more layers to the previous ggplot using the  +  operator, so the code is explicit as to which layers were added and in the order they were added. Examples: require ( ggplot2 ) ## Loading required package: ggplot2 ## Warning: package 'ggplo...

Ggplot2 package (part2)

In the previous post  ggplot2 package (Part1)  ( https://dataworldblog.blogspot.com.es/2017/07/ggplot2-package-part1.html ) we cover some plots using  ggplot2 , here we will cover Barplots along with how to plot different plots together. Barplot : library ( ggplot2 ) ## Warning: package 'ggplot2' was built under R version 3.4.1 # Barplot one ggplot ( chickwts , aes ( x = feed ) ) + geom_bar ( ) + xlab ( "Feed" ) + ylab ( "Count" ) + ggtitle ( "Chickwts1" ) one two ggplot ( chickwts , aes ( x = feed ) ) + geom_bar ( color = "red" , fill = "pink" , width = 0.5 ) + xlab ( "Feed" ) + ylab ( "Count" ) ggtitle ( "Chickwts2" ) two Grid Lines three ggplot ( chickwts , aes ( x = feed ) ) + geom_bar ( fill = 'steelblue' , width = 0.3 ) + coord_flip ( ) + xlab ( "Feed" ) + ylab ( "Count" ) + theme ( pane...