R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

A normal R code chunk

library(reticulate)
x = 42
print(x)
## [1] 42

Modify an R variable

In the following chunk, the value of x on the right hand side is 42, which was defined in the previous chunk.

x = x + 12
print(x)
## [1] 54

A Python chunk

This works fine and as expected.

x = 42 * 2
print(x) 
## 84

The value of x in the Python session is 84. It is not the same x as the one in R.

Modify a Python variable

x = x + 18 
print(x)
## 102

Retrieve the value of x from the Python session again:

py$x
## [1] 102

Assign to a variable in the Python session from R:

py$y = 1:5

See the value of y in the Python session:

print(y)
## [1, 2, 3, 4, 5]

Python graphics

You can draw plots using the matplotlib package in Python.

import matplotlib.pyplot as plt
plt.plot([0, 2, 1, 4])
plt.show()

girafe
Global warming is mostly caused by human activities. 37.3 (Min) 46.1 (25th) 49 (50th) 52.8 (75th) 74.5 (Max) Percent Belief U.S. Climate Opinion, 2021 Sources: Yale Program on Climate Change Communication (https://climatecommunication.yale.edu/visualizations-data/ycom-us/)