Show Values in Boxplot in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 13:46:44

5K+ Views

The main values in a boxplot are minimum, first quartile, median, third quartile, and the maximum, and this group of values is also called five-number summary. Therefore, if we want to show values in boxplot then we can use text function and provide the five-number summary and labels with fivenum function as shown in the below examples.Example1x

Create Horizontal Boxplot in Base R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 13:46:26

3K+ Views

To create a horizontal boxplot in base R, we can set the horizontal argument inside boxplot function to TRUE. For example, if we have a vector called x then the horizontal histogram of that vector can be created by using the command boxplot(x,horizontal=TRUE).Example1x

Create Normal Random Variables with Specific Correlation in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 13:44:07

648 Views

To create normal random variables with specific correlation between them, we can use mvrnorm function of MASS package. For example, if we want to create two variables of size 10 with means equal to 2 and 4 and standard deviation of 0.5 then it can be done by using the command −mvrnorm(10,mu=c(2,4),Sigma=matrix(c(1,0.5,0.5,1),ncol=2),empirical=TRUE)Example1library(MASS) X

Set Text Position Using geom_text in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 13:43:16

470 Views

To set the text position using geom_text, we can use the value for the X-axis and Y-axis with appropriate positions. We need to make sure that the values we set for both the axes do not lie within the data otherwise the text will be printed on the plot we want to draw and it will become less attractiveExampleConsider the below data frame − Live Demox

Find Percentage for Frequencies in a Vector with Two Decimal Places in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 13:41:25

684 Views

To find the percentage for frequencies stored in a vector with two decimal places can be done with the help of sum function and round function. For example, if we have a vector of frequencies say x then the percentage of these frequencies can be found by using the command round((x/sum(x))*100,2). Check out the below examples to understand how it works.Example1 Live DemoFrequency1

Create Duplicate Matrices and Merge Them in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 13:38:34

443 Views

To create duplicate matrices, we can use replicate function that will repeat the original matrix and if we want to merge those matrices together then we can use rbind with do.call. For example, if we have a matrix called M then creation of it’s one duplicate and merging them together can be done using the command −do.call(rbind,replicate(2,M,simplify=FALSE))Example Live DemoM

Find the Opposite of 'in' in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 13:28:52

5K+ Views

To find the opposite of %in%, we can use negation operator ! (exclamation sign). For example, if we have a data frame df that contains a column say x then to subset df by excluding some values (say 2, 3) we can use the command subset(df,!(x %in% c(2,3))).Example1Consider the below data frame − Live Demox1

Change Size of Dots in Dotplot Using ggplot2 in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 13:28:23

3K+ Views

To change the size of dots in dotplot created by using ggplot2, we can use binwidth argument inside geom_dotplot. For example, if we have a data frame called df that contains a column x for which we want to create the dotplot then the plot with different size of dots can be created by using the command ggplot(df,aes(x))+geom_dotplot(binwidth=2).ExampleConsider the below data frame − Live Demox

Create Transparent Bar Plot Using ggplot2 in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 13:24:21

3K+ Views

To create transparent barplot using ggplot2, we can use alpha argument inside geom_bar function. For example, if we have a data frame called df that contains a categorical column say x and a numerical column say count then the bar plot with transparency can be created by using the command ggplot(df,aes(x,y))+geom_bar(alpha=0.1,stat="identity")ExampleConsider the below data frame − Live Demox

Difference Between Class and typeof Function in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 13:24:02

6K+ Views

The class function in R helps us to understand the type of object, for example the output of class for a data frame is integer and the typeof of the same object is list because data frames are stored as list in the memory but they are represented as a data frame. Check out the below examples with multiple type of objects to understand the differences.Example1 Live Demox1

Advertisements