Server Side Programming Articles

Page 1116 of 2109

How to display tick marks on upper as well as right side of the plot using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 851 Views

To display tick marks on upper as well as right side of the plot, we can create duplicate axes for X as well Y by using scale_x_continuous and scale_y_continuous functions. The argument that will help us in this case is sec.axis and we need to set it to dup_axis as scale_x_continuous(sec.axis=dup_axis()) and scale_y_continuous(sec.axis=dup_axis()). Check out the below example to understand how it can be done.ExampleConsider the below data frame −x

Read More

How to display mean in a boxplot with cross sign in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 394 Views

To display mean in a boxplot with cross sign in base R, we can use the points function and pass the mean with pch = 4 that represents a star, also we can change the color to highlight the mean using col argument and the size of the start can be changed using lwd argument as shown in the below examples.Examplex

Read More

How to perform paired t test in R with a factor column in the data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

When we have a factor column in an R data frame that has two levels and a numerical column then we can apply paired-test on this data frame but the data must be collected for same subjects, otherwise it will not be a paired data. The t.test application on the data discussed here can be done by using the command t.test(y1~x1,data=df), where y1 is the numerical column, x1 is the factor column, and both these columns are stored in data frame called df.ExampleConsider the below data frame −x1

Read More

How to create a blank column with randomization in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 255 Views

To create a blank column with randomization in an R data frame, we can use sample function and pass the blanks with single space. For example, if we want to create a vector say x that will be added in the data frame can be created by using the command −x

Read More

How to generate random numbers with sequence and store in a data frame column in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 922 Views

To generate random numbers with sequence and storing them in a data frame column, we can use sample function with seq. For example, if we want to create a data frame column having random sequence of values of size 50 between 1 to 100 by considering every tenth value then we can use the commanddf

Read More

How to set the range for boxplot in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

By default, R considers the vector or the data frame column values. But if we want to set the range for boxplot in base R, we can use ylim argument within the boxplot function. For example, if we have a vector called x that contains values starting from 21 to 50 and we want to have the range in the boxplot starting from 1 to 100 then we can use the commandboxplot(x,ylim=c(1,100))Examplex

Read More

How to filter rows by excluding a particular value in columns of the R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 4K+ Views

To filter rows by excluding a particular value in columns of the data frame, we can use filter_all function of dplyr package along with all_vars argument that will select all the rows except the one that includes the passed value with negation. For example, if we have a data frame called df and we want to filter rows by excluding value 2 then we can use the commanddf%>%filter_all(all_vars(.!=2))ExampleConsider the below data frame −x1

Read More

How to find the number of levels in R for a factor column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

To find the number of levels in R for a factor column, we can use length function along with unique function. For example, if we have a data frame called df that contains a factor column X then we can find the number of levels in the factor column using the command −length(unique(df$X))ExampleConsider the below data frame −x1

Read More

How to create boxplot in base R with higher width of the box lines?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 284 Views

To create boxplot in base R with higher width of the box lines, we can use the boxlwd argument inside boxplot function. For example, if we have a vector called x then we can create the boxplot with higher width of the box lines using the command −boxplot(x,boxlwd=5)Examplex

Read More

How to replace a particular value in R data frame with a new value?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

To replace a particular value in R data frame with a new value, we can use ifelse function where the new value will be placed after the condition and if the column values do not match the condition then the same column will be placed. For example, if we have a data frame called df that contains a column x having 20 values and some of them are 5 and if we want to replace 5 with 2 then we can use the command df$x

Read More
Showing 11151–11160 of 21,090 articles
Advertisements