This notebook demonstrates four types of visualizations using
built-in R datasets including mtcars and
Orange.
# Load the necessary library for advanced plotting
if (!require("ggplot2")) install.packages("ggplot2")
trying URL 'http://rspm/default/__linux__/noble/latest/src/contrib/cpp11_0.5.3.tar.gz'
trying URL 'http://rspm/default/__linux__/noble/latest/src/contrib/farver_2.1.2.tar.gz'
trying URL 'http://rspm/default/__linux__/noble/latest/src/contrib/labeling_0.4.3.tar.gz'
trying URL 'http://rspm/default/__linux__/noble/latest/src/contrib/RColorBrewer_1.1-3.tar.gz'
trying URL 'http://rspm/default/__linux__/noble/latest/src/contrib/viridisLite_0.4.3.tar.gz'
trying URL 'http://rspm/default/__linux__/noble/latest/src/contrib/gtable_0.3.6.tar.gz'
trying URL 'http://rspm/default/__linux__/noble/latest/src/contrib/isoband_0.3.0.tar.gz'
trying URL 'http://rspm/default/__linux__/noble/latest/src/contrib/S7_0.2.1.tar.gz'
trying URL 'http://rspm/default/__linux__/noble/latest/src/contrib/scales_1.4.0.tar.gz'
trying URL 'http://rspm/default/__linux__/noble/latest/src/contrib/withr_3.0.2.tar.gz'
trying URL 'http://rspm/default/__linux__/noble/latest/src/contrib/ggplot2_4.0.2.tar.gz'
The downloaded source packages are in
‘/tmp/Rtmp1EWMko/downloaded_packages’
library(ggplot2)
ggplot(Orange, aes(x = age, y = circumference, color = Tree)) +
geom_line(linewidth = 1) +
geom_point() +
labs(title = "Line Graph: Growth of Orange Trees",
x = "Age (days since 1968)",
y = "Circumference (mm)") +
theme_light()
ggplot(Orange, aes(x = age, y = circumference, color = Tree)) +
geom_line(linewidth = 1) +
geom_point() +
labs(title = "Line Graph: Growth of Orange Trees",
x = "Age (days since 1968)",
y = "Circumference (mm)") +
theme_light()
ggplot(mtcars, aes(x = factor(cyl), fill = factor(gear))) +
geom_bar(position = "stack") +
labs(title = "Stacked Vertical Bar: Cylinders by Gear Count",
x = "Number of Cylinders",
y = "Count of Cars",
fill = "Gears") +
theme_bw()
ggplot(mtcars, aes(x = factor(cyl), fill = factor(gear))) +
geom_bar(position = "stack") +
coord_flip() +
labs(title = "Stacked Horizontal Bar: Cylinders by Gear Count",
x = "Number of Cylinders",
y = "Count of Cars",
fill = "Gears") +
theme_classic()