Advertisement

plot() Function in R (8 Examples) | How Plot Data in RStudio | density() & lines()

plot() Function in R (8 Examples) | How Plot Data in RStudio | density() & lines() How to apply the plot function in the R programming language. More details:
R code of this video tutorial:

##### Example Data
set.seed(1919) # Create example data
x1 <- rnorm(1000)
y1 <- x1 + rnorm(1000)

##### Example 1
plot(x1, y1) # Apply plot function

##### Example 2
plot(x1, y1) # Apply plot function
abline(lm(y1 ~ x1), col = "red") # Draw regression line

##### Example 3
plot(density(x1)) # Plot density

##### Example 4
plot(density(x1)) # Plot multiple densities
lines(density(y1), col = "red")

##### Example 5
plot(x1, y1, # Modify title and axis labels
main = "This is my Plot",
xlab = "X-Values",
ylab = "Y-Values")

##### Example 6
group <- rbinom(1000, 1, 0.3) + 1 # Create group variable
plot(x1, y1, # Create plot with groups
main = "This is my Plot",
xlab = "X-Values",
ylab = "Y-Values",
col = group,
pch = group)

##### Example 7
legend("topleft", # Add legend to plot
legend = c("Group 1", "Group 2"),
col = 1:2,
pch = 1:2)

##### Example 8
x2 <- seq(- 5, 5, 0.01) # Create sequence
y2 <- cos(x2) # Cosinus of sequence
plot(x2, y2) # Plot a function in R

plot function r,plot data in r,r programming plot(),plot density lines functions r,r plot,plot r,statistics globe,statisticsglobe.com,statistical programming,r programming,statistics,r programming language,r statistics,rstudio,r language,r tutorial,learn r,r code,r programming tutorial,

Post a Comment

0 Comments