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
We can create a circle in R by using draw.circle function of plotrix package and if we want to have vertical lines inside the circle then density and angle arguments will be used. The density argument will create the lines and angle argument will set the direction of those lines.For vertical lines the angle will be 270 and the number of lines depends on the value of density argument.Check out the below Examples to understand how different values of density create lines inside the circle.ExampleTo create a circle in R, use the code given below −plot(1:10, type="n")OutputIf you execute the ... Read More
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
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
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
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
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
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
When we large number of values in each element of a list in R, we might want to have a look at some top values to understand the data characteristics. For this purpose, we can extract first n values from each element in an R list by using lapply function along with head function as shown in the below given examples.Example 1Following snippet creates a list −List1
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP