You have two vectors and you want to plot them.
x_values <- rnorm(n = 20 , mean = 5 , sd = 8) #20 values generated from Normal(5,8) y_values <- rbeta(n = 20 , shape1 = 500 , shape2 = 10) #20 values generated from Beta(500,10)
If you want to make a plot which has the
y_values in vertical axis and the
x_valuesin horizontal axis, you can use the following commands:
plot(x = x_values, y = y_values, type = "p") #standard scatter-plot plot(x = x_values, y = y_values, type = "l") # plot with lines plot(x = x_values, y = y_values, type = "n") # empty plot
You can type
?plot() in the console to read about more options.
You have some variables and you want to examine their Distributions
#boxplot is an easy way to see if we have some outliers in the data. z<- rbeta(20 , 500 , 10) #generating values from beta distribution z[c(19 , 20)] <- c(0.97 , 1.05) # replace the two last values with outliers boxplot(z) # the two points are the outliers of variable z.
Easy way to draw histograms
hist(x = x_values) # Histogram for x vector hist(x = x_values, breaks = 3) #use breaks to set the numbers of bars you want
If you want to visualize the frequencies of a variable just draw pie
First we have to generate data with frequencies, for example :
P <- c(rep('A' , 3) , rep('B' , 10) , rep('C' , 7) ) t <- table(P) # this is a frequency matrix of variable P pie(t) # And this is a visual version of the matrix above