library(tidyverse) library(modeldata) ?ggplot view(crickets)
ggplot(crickets, aes(x = temp, y = rate, color = species))+ geom_point() + labs(x = ‘Temperature’, y = ‘Chirp rate’, color = ‘Species’, title = ‘Cricket chirps’, caption = ‘McDonald(2009)’)
ggplot(crickets, aes(x=temp, y=rate))+ geom_point(color=‘red’, # color of the points size=2, # size of the points displayed alpha=.5, shape = ‘square’)+ # the format of the data displayed can be changed labs(x=‘Temperature’, y=‘Chirp Rate’, title = ‘Cricket chirps’, caption = ‘Source: McDonald (2009)’)
ggplot(crickets, aes(x = temp, y = rate, color = species))+ geom_point() + geom_smooth(methods=‘lm’, se = FALSE) labs(x = ‘Temperature’, y = ‘Chirp rate’, color = ‘Species’, title = ‘Cricket chirps’, caption = ‘McDonald(2009)’)
# Other Plots
ggplot(crickets, aes(x=rate)) + geom_histogram(bins = 10) # one quantitative variable
ggplot(crickets, aes(x=rate)) + geom_freqpoly(bins = 10)
ggplot(crickets, aes(x=species))+ geom_bar(color=‘black’, fill = ‘white’)
ggplot(crickets, aes(x=species, fill=species))+ geom_bar(show.legend=FALSE)+ scale_fill_brewer(palette= ‘Dark2’)
ggplot(crickets, aes(x=species, y=rate, color=species))+ geom_boxplot(show.legend=FALSE)+ scale_fill_brewer(palette=‘Dark2’) + theme_minimal() ?theme_minimal()
#faceting
ggplot(crickets, aes(x=rate, fill=species))+ geom_histogram(bins=15)+ scale_fill_brewer(palette=‘Dark2’)
ggplot(crickets, aes(x=rate, fill=species))+ geom_histogram(bins=15, show.legend=FALSE)+ facet_wrap(~species)+ scale_fill_brewer(palette=‘Dark2’)
?facet_wrap
ggplot(crickets, aes(x=rate, fill=species))+ geom_histogram(bins=15, show.legend=FALSE)+ facet_wrap(~species, ncol=1)+ scale_fill_brewer(palette=‘Dark2’)