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:

#One categorical and one continuous variable (Bar Chart)
# Sample data
data <- data.frame(Category = c("A", "B", "C", "D", "E"), Value = c(10, 15, 8, 20, 12))

# Create a bar chart
barplot(data$Value, names.arg = data$Category, col = "skyblue", main = "Categorical vs. Continuous", xlab = "Category", ylab = "Value")

Including Plots

You can also embed plots, for example:

#One continuous variable (Histogram)
# Sample data
data <- rnorm(100)

# Create a histogram
hist(data, col = "green", main = "Histogram", xlab = "Value", ylab = "Frequency")

#Two continuous variables (Scatter Plot)
# Sample data
x <- rnorm(100)
y <- rnorm(100)

# Create a scatter plot
plot(x, y, col = "blue", main = "Scatter Plot", xlab = "X", ylab = "Y")

# Load the airquality dataset
data(airquality)

# Create a horizontal bar chart for the "Ozone" attribute
barplot(airquality$Ozone, names.arg = airquality$Month, col = "skyblue",
        main = "Ozone Distribution by Month", xlab = "Month", ylab = "Ozone")

# Create a histogram for the "Wind" attribute
hist(airquality$Wind, col = "green", main = "Wind Speed Distribution", xlab = "Wind Speed", ylab = "Frequency")

# Create a scatter plot for "Wind" vs. "Ozone"
plot(airquality$Wind, airquality$Ozone, col = "blue", main = "Wind Speed vs. Ozone", xlab = "Wind Speed", ylab = "Ozone")

# Bar chart showing the number of cars by the number of cylinders
barplot(table(mtcars$cyl), main = "Number of Cars by Cylinders", xlab = "Cylinders", ylab = "Count")

# Line plot showing the trend of car horsepower over time
plot(mtcars$hp, type = "l", main = "Horsepower Over Time", xlab = "Car Index", ylab = "Horsepower")

# Scatter plot showing the relationship between car weight and miles per gallon
plot(mtcars$wt, mtcars$mpg, main = "Car Weight vs. MPG", xlab = "Weight", ylab = "Miles per Gallon")

# Count the number of cars by the number of cylinders
cylinder_counts <- table(mtcars$cyl)

# Create a pie chart
pie(cylinder_counts, main = "Car Counts by Cylinders")

# Box plot showing the distribution of car miles per gallon
boxplot(mtcars$mpg, main = "Miles per Gallon Distribution", ylab = "Miles per Gallon")

# Histogram showing the distribution of car horsepower
hist(mtcars$hp, main = "Horsepower Distribution", xlab = "Horsepower", ylab = "Frequency")

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