Visualizing the R for Excel workshop with both R and Python
Author
Jeffrey Sumner
Published
May 8, 2023
Reading data into R/Python
Below are the ways that we will be reading in our data from this post’s local data/ directory with both R and python. For R users, we will use the readr:: and readxl:: packages while python users will read data with pandas. Let’s view the examples below.
Below we will create our first basic visual using both R and python. With the R code we will only use ggplot2 to create this visual. For python, we will use plotnine which uses R’s ggplot2 syntax.
import matplotlib.pyplot as pltfrom plotnine import ggplot, aes, geom_lineplt.switch_backend('agg')# Creating the plotplot = ( ggplot(data=ci_np, mapping=aes(x='year', y='visitors'))+ geom_line())# Displaying the plotprint(plot)
<ggplot: (640 x 480)>
Now that we have a few basic plots created across each package/library, let’s create a base plot object and create variations off of it. This will be done similar to the R for Excel