Google News
logo
R - Interview Questions
How to make a scatterplot in R?
Scatterplot is a graph which shows many points plotted in the Cartesian plane. Each point holds two values that are present on the x-axis and y-axis. The simple scatterplot is plotted using plot() function.
 
The syntax for scatterplot is :
plot(x,y,main,xlab,ylab,xlim,ylim,axes)​

 

Where
 
x is the data set whose values are the horizontal coordinates
 
y is the data set whose values are the vertical coordinates
 
main is the tile in the graph
 
xlab and ylab is the label in the horizontal and vertical axis
 
xlim and ylim are the limits of values of x and y used in the plotting
 
axes indicate whether both axes should be there on the plot.
plot(x = input$wt,y = input$mpg,
xlab = “Weight”,
ylab = “Mileage”,
xlim = c(2.5,5)
ylim = c(15,30)
main = “Weight vs Mileage”
)
Advertisement