R Code.A list of useful R code for Master, PhD and Post Graduate
|
List of R Code Used by E3B Graduate Students |
Graphs and Figures:
Commands for different graphs:
Commands to edit figures:
General Tips:
Commands for different graphs:
- plot(x-value, y-value): used to create a scatter plot
- hist(vector_name): used to create a histogram
- To plot density instead of frequency, add freq = False in the parentheses
- barplot(x-value, y-value): used to create a bar graph
- lines(x-value, y-value): used to create a line graph
- boxplot(y-value~x-value): used to create a box plot
Commands to edit figures:
- main = "Title": used to set the title of the figure
- xlab = "X axis": used to set the title of the x-axis
- ylab = "Y axis": used to set the title of the y-axis
- col = "color": used to set the color of the data points/bars/etc. of the figure
- xlim = c(min, max): used to set the range for the x-axis
- ylim = c(min, max): used to set the range for the y-axis
General Tips:
- To specify which x or y values to use, you can either use dataset$column_name or specify the column names and add data = dataset within the parentheses (ie. "plot(dataset$column1, dataset$column2)" or "plot(column1, column2, data=dataset)")
- The package "ggplot" can be used to create more detailed figures with more ways to edit them