<jupyter_start><jupyter_text>PlottingLet's learn how to plot some simple graphs.<jupyter_code>set.seed(37)<jupyter_output><empty_output><jupyter_text>Box plotHere's an example box plot.<jupyter_code>x <- rnorm(1000, mean=0, sd=1)
y <- rnorm(1000, mean=5, sd=5)

options(repr.plot.width=4, repr.plot.height=4)

boxplot(x, y, names=c('x', 'y'), xlab='variables', ylab='value', col='gray90')
title('Box Plot')<jupyter_output><empty_output><jupyter_text>We may also change the box plot to be horizontal.<jupyter_code>x <- rnorm(1000, mean=0, sd=1)
y <- rnorm(1000, mean=5, sd=5)

options(repr.plot.width=4, repr.plot.height=4)

boxplot(x, y, names=c('x', 'y'), xlab='variables', ylab='value', col='gray90', horizontal=TRUE)
title('Box Plot')<jupyter_output><empty_output><jupyter_text>Scatter plot<jupyter_code>x <- rnorm(300, mean=0, sd=1)
y <- rnorm(300, mean=5, sd=5)

options(repr.plot.width=4, repr.plot.height=4)

plot(x, y, pch=3)
abline(lm(y ~ x), lty='dotted', lwd=2, col='red')
title('Scatter Plot')<jupyter_output><empty_output><jupyter_text>Pairs plotThe `pairs plot` shows multiple scatter plots on one graphic.<jupyter_code>x <- rnorm(300, mean=0, sd=1)
y <- rnorm(300, mean=1.5, sd=2.0)
z <- 5 + 3 * x - 2 * y + rnorm(300, mean=0, sd=1)

data <- data.frame(
    x = x,
    y = y,
    z = z
)

options(repr.plot.width=5, repr.plot.height=5)

pairs(data)<jupyter_output><empty_output><jupyter_text>Line plot<jupyter_code>t <- seq(1:100)
s <- sin(t) + rnorm(100, mean=1, sd=1)

options(repr.plot.width=10, repr.plot.height=5)

plot(t, s, type='l')<jupyter_output><empty_output><jupyter_text>Pie charts<jupyter_code>e <- c(100, 50, 200)
l <- c('business', 'social', 'military')
c <- c('gray40', 'gray50', 'gray90')

options(repr.plot.width=4, repr.plot.height=4)

pie(e, labels=l, col=c)<jupyter_output><empty_output><jupyter_text>Dot charts<jupyter_code>e <- c(100, 50, 200)
l <- c('business', 'social', 'military')

options(repr.plot.width=4, repr.plot.height=4)

dotchart(e, labels=l)<jupyter_output><empty_output><jupyter_text>Bar chart<jupyter_code>e <- c(100, 50, 200)
l <- c('business', 'social', 'military')

options(repr.plot.width=4, repr.plot.height=4)

barplot(e, names=l)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.194957226474561, 'fraction_numerical': 0.05312922107158938, 'mean_word_length': 6.715277777777778, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '451264', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1051, 'n_tokens_neox': 953, 'n_words': 169, 'path': 'sphinx/r-intro/source/plot.ipynb', 'repo_name': 'oneoffcoder/books', 'size': '2221'}