Skip to content

Instantly share code, notes, and snippets.

@rich-iannone
Last active February 11, 2016 01:36
Show Gist options
  • Save rich-iannone/870b6d2876334f8e0ed0 to your computer and use it in GitHub Desktop.
Save rich-iannone/870b6d2876334f8e0ed0 to your computer and use it in GitHub Desktop.
How to plot some Iris data with DiagrammeR and export as a PDF or PNG.
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
library(DiagrammeRsvg)
library(magrittr)
# Create three groups (Setosa, Versicolor, and Virginica)
# of x,y datapoints for petal length (x) and petal width (y)
setosa <-
create_xy_pts(
series_label = "Setosa",
x = subset(iris, Species == "setosa")$Petal.Length,
y = subset(iris, Species == "setosa")$Petal.Width,
line_color = "red")
versicolor <-
create_xy_pts(
series_label = "Versicolor",
x = subset(iris, Species == "versicolor")$Petal.Length,
y = subset(iris, Species == "versicolor")$Petal.Width,
line_color = "green")
virginica <-
create_xy_pts(
series_label = "Virginica",
x = subset(iris, Species == "virginica")$Petal.Length,
y = subset(iris, Species == "virginica")$Petal.Width,
line_color = "blue")
# Add these xy points to the `create_xy_graph()` function
# and add axis titles and a heading
iris_length_width <-
create_xy_graph(
setosa,
versicolor,
virginica,
x_name = "Petal Length",
y_name = "Petal Width",
heading = c("#Iris Dataset*",
"#####Plot produced February 5, 2016"),
footer = c("####*Consists of 50 samples.",
"####All in units of centimeters."),
legend_offset = c(0, 6),
bg_color = "white")
# View the graph
iris_length_width %>% render_graph
# Export the graph to a PDF file
iris_length_width %>% export_graph("iris.pdf")
# Export the graph to a PNG file
iris_length_width %>% export_graph("iris.png")
@rich-iannone
Copy link
Author

The output:

iris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment