Load data from working directory. I named my file frog_data
head(frog_data)
load ggplot2 package
library(ggplot2)
ggplot asks four basic things from you: 1. what is the dataframe? 2. which information within the dataframe to graph? 3. what kind of graph to make? 4. how do you want the graph to look?
For question one ,the first item you tell ggplot is what the dataframe is called: ‘frog_data’.
[an aside, I like adding ’_data’ when its a dataframe because if you are working on a big analysis project you will often make lots of items within your R workflow, for me adding what kind of item I made (_data, _graph, _summary) at the end is helpful when I am looking for something I did].
So for question 1. you can say:
frog_gender_mass_boxplot<-ggplot(frog_data)
frog_gender_mass_boxplot

This just makes a blank figure, all you did was tell ggplot where to look for data. For question 2, you next add where in the dataframe for ggplot to take data to make a figure using the aes() command. The ‘,’ tells ggplot you are providing it where the data of interest is.
frog_gender_mass_boxplot<-ggplot(frog_data, aes(x = frog_data$gender, y = frog_data$mass))
frog_gender_mass_boxplot

Now it gave you the x and y axis but it still hasn’t produced a plot. To produce a boxplot, you add the third step: + geomboxplot(). But, you have to tell ggplot what the grouping variable is to make the boxplot: + geom_boxplot(aes(group = frog_data$gender)). If you want it to make a boxplot of the variable in the entire dataset: + geom_boxplot(aes(group x=“”)). In ggplot, different kinds of graphs are denoted by geom_, so geom_boxplot is a box plot, geom_histogram is a histogram
frog_gender_mass_boxplot<-ggplot(frog_data, aes(x = frog_data$gender,y = frog_data$mass)) + geom_boxplot(aes(group = frog_data$gender))
frog_gender_mass_boxplot

So now you have a boxplot, but the x and y labels are not very nice. The remainder of the questions ggplot ask as part of step 4 are what to do to the figure to make it look how you want. Typically you want to change the x and y axis labels to something not in R-speak, so you add: + xlab(“Gender”)+ ylab(“Mass (g)”)
frog_gender_mass_boxplot<-ggplot(frog_data, aes(x = frog_data$gender,y = frog_data$mass)) + geom_boxplot(aes(group = frog_data$gender)) + xlab("Gender")+ylab("Mass (g)")
frog_gender_mass_boxplot

After these four basic steps, you can keep adding commands to make the plot look how you want. For example, ggplot has some preset themes that change the overall color of the graph and line shading. The graph above uses:
+ theme_gray() which is the preset theme. But, if you look in the help vignette in Rstudio there are other presets. You can also make your own themes too, if you have lots of spare time on your hand. Here is code for a different theme preset that is just a white background and no gridlines: + theme_classic()
ggplot(frog_data, aes(x = frog_data$gender, y = frog_data$mass)) + geom_boxplot(aes(group = frog_data$gender)) + xlab("Gender") + ylab("Mass (g)") + theme_classic()

There is a lot of customization you can do, but you can make nearly all the graphs you need with those four basic commands in ggplot.
LS0tCnRpdGxlOiAiUiBOb3RlYm9vayIKb3V0cHV0OgogIGh0bWxfbm90ZWJvb2s6IGRlZmF1bHQKICB3b3JkX2RvY3VtZW50OiBkZWZhdWx0Ci0tLQpMb2FkIGRhdGEgZnJvbSB3b3JraW5nIGRpcmVjdG9yeS4gSSBuYW1lZCBteSBmaWxlIGZyb2dfZGF0YQoKaGVhZChmcm9nX2RhdGEpCmBgYHtyLCBlY2hvPVRSVUUsIG1lc3NhZ2U9RkFMU0UsIHdhcm5pbmc9RkFMU0V9CmZyb2dfZGF0YSA8LSByZWFkX2Nzdigifi9EZXNrdG9wL01FUy9SRFFNIFNwcmluZyAyMDIwL1dlZWsgMi9SRFFNX2xhYjFfV2VlazIvZnJvZ19kYXRhLmNzdiIpCmhlYWQoZnJvZ19kYXRhKQpgYGAKCmxvYWQgZ2dwbG90MiBwYWNrYWdlCmBgYHtyfQpsaWJyYXJ5KGdncGxvdDIpCmBgYAoKZ2dwbG90IGFza3MgZm91ciBiYXNpYyB0aGluZ3MgZnJvbSB5b3U6CjEuIHdoYXQgaXMgdGhlIGRhdGFmcmFtZT8gCjIuIHdoaWNoIGluZm9ybWF0aW9uIHdpdGhpbiB0aGUgZGF0YWZyYW1lIHRvIGdyYXBoPyAKMy4gd2hhdCBraW5kIG9mIGdyYXBoIHRvIG1ha2U/IAo0LiBob3cgZG8geW91IHdhbnQgdGhlIGdyYXBoIHRvIGxvb2s/CgpGb3IgcXVlc3Rpb24gb25lICx0aGUgZmlyc3QgaXRlbSB5b3UgdGVsbCBnZ3Bsb3QgaXMgd2hhdCB0aGUgZGF0YWZyYW1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