From c72c34aa7c76176de887ae04c89d7f0831edceb4 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Mon, 11 Mar 2019 09:27:17 +0000 Subject: [PATCH] update vignette --- docs/articles/poppr_manual.html | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/articles/poppr_manual.html b/docs/articles/poppr_manual.html index f47bbe1e..b1d2fcce 100644 --- a/docs/articles/poppr_manual.html +++ b/docs/articles/poppr_manual.html @@ -86,7 +86,7 @@

Data import and manipulation in poppr version 2.8.2

Zhian N. Kamvar and Niklaus J. Grünwald

-

2019-03-10

+

2019-03-11

Source: vignettes/poppr_manual.Rmd @@ -1642,30 +1642,30 @@

Manipulating Graphics

-

Poppr utilizes ggplot2 to produce many of its graphs. One advantage it gives the user is the ability to manipulate these graphs. With base R graphs, the only manipulation that can be performed is by adding elements to the graph. It is a static image. The ggplot graphs are actually represented as objects in your R environment. We can use the function last_plot() from ggplot2 to be able to grab the plot that was plotted last in our window. Let’s illustrate this using a MLG bar graph from the Aeut data set.

+

Poppr utilizes ggplot2 to produce many of its graphs. One advantage it gives the user is the ability to manipulate these graphs. With base R graphs, the only manipulation that can be performed is by adding elements to the graph. It is a static image. The ggplot graphs are actually represented as objects in your R environment. We can use the function last_plot() from ggplot2 to be able to grab the plot that was plotted last in our window. Let’s illustrate this using a MLG bar graph from the Aeut data set.

library("poppr")
 library("ggplot2")
 data(Aeut)
 Aeut.tab <- mlg.table(Aeut)

- -

We’ve captured our plot using last_plot() and now we can manipulate it. One common need is to change the title. We can easily do that with the function ggtitle(). Let“s say we wanted to label it”Aphanomyces euteiches multilocus genotype distribution". We would use ggtitle(Aphanomyces euteiches multilocus genotype distribution). Unfortunately, we need italics for a latin binomial. One way to acheive this is by using the expression() function and declaring which text needs to be italicized.

+ +

We’ve captured our plot using last_plot() and now we can manipulate it. One common need is to change the title. We can easily do that with the function ggtitle(). Let“s say we wanted to label it”Aphanomyces euteiches multilocus genotype distribution". We would use ggtitle(Aphanomyces euteiches multilocus genotype distribution). Unfortunately, we need italics for a latin binomial. One way to acheive this is by using the expression() function and declaring which text needs to be italicized.

myTitle <- expression(paste(italic("Aphanomyces euteiches"), 
                       " multilocus genotype distribution"))
 (pt <- p +
-   ggtitle(myTitle) +
-   xlab("Multilocus genotype")) # We can label the x axis, too
+ ggtitle(myTitle) + + xlab("Multilocus genotype")) # We can label the x axis, too

-

Let"s say we wanted to remove the grey background. We could use the theme() function to do this, or we could use a theme already implemented in ggplot2 called theme_bw().

- +

Let"s say we wanted to remove the grey background. We could use the theme() function to do this, or we could use a theme already implemented in ggplot2 called theme_bw().

+

Uh-oh. The x axis labels are now horizontal when they should be vertical. Since it"s the overall distribution we’re interested in, we don’t really need them anyways. We can remove them with axis.text.x and axis.ticks.x (we’ll also remove the x axis gridlines because they’re ugly).

-
(ptta <- ptt + theme(axis.text.x = element_blank()) +
-  theme(axis.ticks.x = element_blank()) +
-  theme(panel.grid.major.x = element_blank()))
+
(ptta <- ptt + theme(axis.text.x = element_blank()) +
+  theme(axis.ticks.x = element_blank()) +
+  theme(panel.grid.major.x = element_blank()))

And, if for some bizarre reason, you liked the color gradient in poppr version 1, you can get that back by adding the fill aesthetic:

-
(ptttaf <- ptta + aes(fill = count))
+
(ptttaf <- ptta + aes(fill = count))

This allows you to produce publication quality graphs directly in R. Please see Hadley Wickham“s ggplot2 package for more details (Wickham 2009). Note that if you don”t like using ggplot2, you can access the data in the ggplot2 object and plot the data yourself:

head(p$data)
@@ -1731,7 +1731,7 @@

ggplot2 is a fantastic package that poppr uses to produce graphs for the mlg.table(), poppr(), and ia() functions. Saving a plot with ggplot2 is performed with one command after your plot has rendered:

data(nancycats) # Load the data set.
 poppr(nancycats, sample = 999) # Produce a single plot.
-ggsave("nancycats.pdf")
+ggsave("nancycats.pdf")

Note that you can name the file anything, and ggsave will save it in that format for you. The details are in the documentation and you can access it by typing help(ggsave) in your R console. The important things to note are that you can set a width, height, and unit. The only downside to this function is that you can only save one plot at a time. If you want to be able to save multiple plots, read on to the next section.

@@ -1826,7 +1826,7 @@

Stoddart, J.A., and J.F. Taylor. 1988. “Genotypic Diversity: Estimation and Prediction in Samples.” Genetics 118 (4): 705–11. http://www.genetics.org/content/118/4/705.abstract.

-

Wickham, Hadley. 2009. Ggplot2: Elegant Graphics for Data Analysis. Springer New York. http://ggplot2.org/book/.

+

Wickham, Hadley. 2009. Ggplot2: Elegant Graphics for Data Analysis. Springer New York.