Visualization in R
Melanoma is a serious form of skin cancer that arises from the pigment-containing cells known as melanocytes. Understanding factors that contribute to melanoma development and progression is crucial for diagnosis and treatment. In this blog post, we'll explore a dataset containing information about patients diagnosed with melanoma and visualize the relationship between age, sex, thickness, and ulcer presence using R programming.
To produce graphics in R, there are three types:
1. Base graphics
2. Lattice
3. ggplot2
1. Base graphics:
Base graphics already exist in the R installation. It allows to create a wide range of two-dimensional plots, including scatterplots, line graphs, bar graphs, and more. 'plot' function is implemented which creates a scatterplot of a dataset. 'pch=21' is used to set the type of plotting to a filled circle with a solid fill. Different color palletes can be used, but for this code 'rainbow()' and 'heat.colors()' is utilized. The title of the plot can be added to the graph using the 'main' function. 'bg' defines the fill color of the circle. 'cex' controls the size of the points in the plot (character expansion). Finally, this code produces a scatter plot of the relationship between age vs thickness and age vs ulcer.
2. Lattice:
The lattice package in R provides functions that can be used to create high-level graphics such as trellis plots. These functions offer an additional layer of abstraction when compared to base graphics and are highly customizable. To use these functions, you need to install the lattice package and then load it using the library() function.
Once loaded, the 'xyplot' function is used to plot the relationship between the age and thickness. The 'pch' function sets the type of plot, while the 'cex' function controls the size of the points in the plot (character expansion).
Each component is added to the plot as a layer that never been done in statistical programming language. It creates complex and highly customizable visualizations.It takes two primary arguments, data and aes(). Aesthetic mapping to pass to be plotted.
To create ggplot2 graphics in R, the 'ggplot2' package is installed and loaded using the 'library()' function. The 'ggplot2' function is implemented in the 'melanoma' dataset. Plots convey information through various aspects of their aesthetics. 'x' is defined by 'age', and 'y' is defined by 'thickness'. The sign '+' was added to give a new layer with 'geom_line()' which gives line to the plot. The code 'linetype=3' sets the line type to a dashed line.'geom_point()' function adds points to the plot.
Please find the code in Git Repo via URL | Visualization.R |
Comments
Post a Comment