Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 12 of 196

How to display tilde ggplot2 graph in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 453 Views

Let’s say we want to display tilde sign at a particular position in histogram using ggplot2 graph. In this situation, we can use geom_text function and pass all the text with label argument inside aes where tilde will be written as %~%.For Example, if we want to display X follows Normal Distribution then we can write it as −geom_text(aes(label="X %~% Normal Distribution",x=0,y=200),parse=TRUE)Here, x=0 and y=200 is the position of the label in the histogram.ExampleConsider the below data frame −x

Read More

How to create a 90-degree arc in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 330 Views

To create a 90-degree arc in R, we can use draw.arc function of plotrix package where we can use deg2 argument. Since, a 90-degree can be drawn in four ways; we need to pass the degree depending on the position of the arc we want to display.Check out an Example explained below.ExampleTo create a 90-degree arc in R, add the following code −plot(1:10, type="n")OutputIf you execute the above given snippet, it generates the following Output −To create a 90-degree arc in R, add the following code to the above snippet −plot(1:10, type="n") draw.arc(5, 5, 2, deg2=90, col="blue")OutputIf you execute all ...

Read More

How to create a circle with different color border in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 557 Views

We can create a circle in R by using draw.circle function of plotrix package and default border color of the circle is black. If we want to change the border color of a circle then we can use border argument and pass the desired colors.For Example, if we want to create a blue colored circle then, we can use the below mentioned command −draw.circle(5, 5, 2, border="blue")Check out the below Example to understand how it works.ExampleTo create a colored circle add the following code to the above snippet −plot(1:10, type="n")OutputIf you execute the above given snippet, it generates the following ...

Read More

How to fill bars of a bar plot created using ggplot2 with colors based on frequency?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 886 Views

To fill bars in a bar plot using ggplot2 in R with colors based on frequency, we can use fill argument with count.For Example, if we have a data frame called df that contains a single column X that contains repeated values and we want to create bar plot of values in X based on their frequencies then we can use the below command −ggplot(df)+geom_bar(aes(X,fill=..count..))ExampleConsider the data frame given below −x

Read More

How to create a matrix with equal rows in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 823 Views

If we have a single row for a matrix then creation of a matrix with equal rows can be easily done with the help of rep function and if we do not have the row then we would need to pass the row value inside rep function.Check out the below examples to understand how to create a matrix with equal rows if one row is known.Example 1Consider the below vector −Row_1

Read More

How to impute missing values by random value for a single column in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 794 Views

To impute missing values by random value for a single column in R, we can use impute function from Hmisc package.For example, if we have a data frame called that contains a column say C which has some missing values then we can use the below given command to fill those missing values randomly −df$C

Read More

How to create scatterplot using data frame columns in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 3K+ Views

To create scatterplot using data frame columns, we need to convert the data frame columns into a variable and the value for each column will be read in a new column against each column name. This can be done with the help of melt function in reshape2 package.After that we can use ggplot function to create the scatterplot with new data frame as shown in the below example.ExampleFollowing snippet creates a sample data frame −x1

Read More

How to multiply each element of a larger vector with a smaller vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 248 Views

To multiply each element of a larger vector with a smaller vector, we can perform outer product calculation with the help of %o% operator.For example, if we have two vectors say x and y where x is of shorter length than y then we can multiply each element of y with each element of x by using the command given below −x%o%yCheck out the below examples to understand how it works.Example 1To multiply each element of a larger vector with a smaller vector, use the code given below −x1

Read More

How to extract unique rows by categorical column of a data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 401 Views

If we have categorical data in a data.table object and some values are duplicate then we might want to extract unique rows from that object.To extract unique rows by categorical column of a data.table object, we can use unique function and define the columns with by argument as shown in the below examples. To understand how the extraction is done check out the below examples.Example 1Following snippet creates a data.table object −library(data.table) grp

Read More

How to extract diagonal elements of a matrix in R without using diag function?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 2K+ Views

The diagonal elements of a matrix occur at the position where column and row indices are same hence, we can make use of those indices to extract diagonal elements of a matrix if we do not want to use diag function.For example, if we have a matrix called M then diagonal elements of M can be extracted by using the command given below − M[row(M)==col(M)]Check out the below examples to understand how it works.Example 1Following snippet creates a matrix −M1

Read More
Showing 111–120 of 1,958 articles
« Prev 1 10 11 12 13 14 196 Next »
Advertisements