Programming Articles - Page 932 of 3363

How to remove end lines from a boxplot in R?

Nizamuddin Siddiqui
Updated on 27-Oct-2021 12:19:07

765 Views

The default boxplot in R has straight lines that display end point(s) excluding outliers. To remove these end lines from a boxplot, we can use staplelty argument and set it to 0.For Example, if we have a vector called X then we can create the boxplot of X by using the command given below −boxplot(X,staplelty=0)ExampleFollowing snippet creates a sample data frame −x

How to check if a data frame has any missing value in R?

Nizamuddin Siddiqui
Updated on 27-Oct-2021 12:13:21

2K+ Views

To check if a data frame has any missing value in R, we can use any function along with is.na function. For Example, if we have a data frame called df then we can use the below command to check whether df contains any missing value or notany(is.na(df))Example 1Following snippet creates a sample data frame −x1

Create a subset of non-duplicate values without the first duplicate from a vector in R.

Nizamuddin Siddiqui
Updated on 27-Oct-2021 11:54:15

192 Views

Generally, the duplicate values are considered after first occurrence but the first occurrence of a value is also a duplicate of the remaining therefore, we might want to exclude that as well.The subsetting of non-duplicate values from a vector in R can be easily done with the help of duplicated function with negation operator as shown in the Examples given below.Example 1Following snippet creates a sample data frame −x1

Create scatterplot for two dependent variables and one independent variable in R.

Nizamuddin Siddiqui
Updated on 11-Nov-2021 04:40:13

2K+ Views

To create scatterplot for two dependent variables and one independent variable, we can use geom_point function and geom_smooth function of ggplot2 package. Both of these functions will be used twice, where we can define the aesthetics of the plot for each dependent variable as shown in the Example below.ExampleFollowing snippet creates a sample data frame −x

How to create pie chart in base R?

Nizamuddin Siddiqui
Updated on 27-Oct-2021 11:40:52

249 Views

A pie chart is a circular representation of data which is created for either nominal data or ordinal data. The slices in the pie chart depend on the magnitude of the data values. If we want to create a pie chart in base R then pie function can be used.For Example, if we have a vector called X then the pie chart for values in X can be created by using the below command −pie(X)ExampleFollowing snippet creates a sample data frame −x

How to find the row products for each row in an R data frame?

Nizamuddin Siddiqui
Updated on 27-Oct-2021 11:26:13

320 Views

To find the row products for each row in an R data frame, we can use rowProds function of matrixStats package but we need to read the data frame as a matrix.For Example, if we have a data frame called df then we can find the row products for each row in df by using the command given below −rowProds(as.matrix(df))Example 1Following snippet creates a sample data frame −x1

How to draw concentric circles with dark borders in R?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 04:32:01

180 Views

To draw concentric circles, we can use draw.circle function of plotrix package where we can put lwd argument but firstly we would need to create a blank graph with plot function as shown below.For Example, we can create three concentric circles at position X=5 and Y=5 having radius of 1, 2, and 3 by using the below command −draw.circle(5, 5, c(1.5, 1, 0.5), col=c("yellow", "green", "orange"), lwd=2)ExampleConsider the following snippet −plot(1:10, type="n")OutputIf you execute the above given snippet, it generates the following Output −Add the following code to the above snippet −plot(1:10, type="n") library(plotrix) draw.circle(5, 5, c(1.5, 1, 0.5), col=c("yellow", ... Read More

How to create matrix diagram in R?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 04:19:21

391 Views

To create matrix diagram, we can use corrplot function of corrplot function. For this purpose, we would need to set is.corr argument to FALSE so that the matrix values will be plotted in the diagram. Otherwise, the corrplot function requires correlation matrix instead of a matrix.Check out the Example given below to understand how it works.ExampleFollowing snippet creates a sample matrix −M

Create a sample of data frame column by excluding NAs in R

Nizamuddin Siddiqui
Updated on 27-Oct-2021 10:40:48

283 Views

To create a random sample by excluding missing values of a data frame column, we can use sample function and the negation of is.na with the column of the data frame.For Example, if we have a data frame called df that contains a column X which has some NAs then we can create a random sample of size 100 of X values by using the following command −sample(df$X[!is.na(df$X)],100,replace=TRUE).Example 1Following is the code snippet to create dataframe −x

Create line chart for mean covered with minimum and maximum in R.

Nizamuddin Siddiqui
Updated on 11-Nov-2021 04:13:33

1K+ Views

To create line chart for mean covered with minimum and maximum in R, we first need to create columns for row means, row minimum, and row maximum after that geom_line function can be used along with geom_ribbon function of ggplot2 package as shown in the below example.ExampleFollowing snippet creates a sample dataframe.x

Advertisements