Increase Thickness of Histogram Lines in Base R

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:32:14

1K+ Views

To increase the thickness of histogram lines in base R, we would need to use par function by defining the thickness size of the line. If we want to do so then line thickness must be defined first before creating the histogram. An example of line size could be line

Find Row Mean for Columns in R Data Frame Ignoring Missing Values

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:30:25

6K+ Views

To find the row mean for columns by ignoring missing values, we would need to use rowMeans function with na.rm. For example, if we have a data frame called df that contains five columns and some of the values are missing then the row means will be calculated by using the command: rowMeans(df,na.rm=TRUE).Consider the below data frame −Example Live Demox1

Deal with Error in Shapiro Test: Sample Size Must Be Between 3 and 5000 in R

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:22:48

4K+ Views

The shapiro.test has a restriction in R that it can be applied only up to a sample of size 5000 and the least sample size must be 3. Therefore, we have an alternative hypothesis test called Anderson Darling normality test. To perform this test, we need load nortest package and use the ad.test function as shown in the below examples.Consider the below data frame −Example Live Demox

Display Positive Sign for X-Axis Labels in R Using ggplot2

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:20:04

541 Views

By default, the positive signs are not displayed in any plot in R. It is well known that if there is no sign seen with any value then it is considered positive, therefore, we do not need the sign but to distinguish between 0 and positive values it could be done. To display positive sign for X-axis labels, we can use scale_x_continuous function.Consider the below data frame −Example Live Demox

Change Size of Plots Using grid.arrange in R

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:15:24

10K+ Views

To change the size of plots arranged using grid.arrange, we can use heights argument. The heights argument will have a vector equal to the number of plots that we want to arrange inside grid.arrange. The size of the plots will vary depending on the values in this vector.Consider the below data frame −Example Live Demox

Create Cumulative Sum Plot in Base R

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:11:00

3K+ Views

To create a cumulative sum plot in base R, we can simply use plot function. For cumulative sums inside the plot, the cumsum function needs to be used for the variable that has to be summed up with cumulation. For example, if we have two vectors say x and y then the plot with cumulative sum plot can be created as plot(x,cumsum(y)).Examplex1

Create a Plot in Base R with Larger Tick Marks

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:08:48

2K+ Views

To create a plot in base R with tick marks of larger size, we can make use of axis function tck argument. The tck argument value will decide the size of the tick mark but since the ticks lie below the plot area hence the value will have a negative associated with it. Therefore, it will be like -0.05. Check out the below examples to understand how it works.Exampleplot(1:10,axes=FALSE,frame=TRUE) axis(1,1:10,tck=-0.02) axis(2,1:10,tck=-0.02)OutputExampleplot(1:10,axes=FALSE,frame=TRUE) axis(1,1:10,tck=-0.05) axis(2,1:10,tck=-0.05)Output

Find Mode for an R Data Frame Column

Nizamuddin Siddiqui
Updated on 06-Feb-2021 12:02:06

3K+ Views

To find the model for an R data frame column, we can create a function and use it for the calculation. The function for mode is created as written below −mode

Change Linetype for geom_vline in R

Nizamuddin Siddiqui
Updated on 06-Feb-2021 11:47:16

8K+ Views

To change the linetype for geom_vline, we can use linetype argument in geom_vline function of ggplot2 package. There are mainly six linetypes that can be used and these values are 0=blank, 1=solid (default), 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash.Consider the below data frame −x

Extract All String Values from a Vector in R with Maximum Lengths

Nizamuddin Siddiqui
Updated on 06-Feb-2021 11:44:17

162 Views

If we have a string vector then all the values in the vector are not likely to be of same size and we might be looking for smaller size or bigger size values. Therefore, if we want to extract all string values from a vector in R with maximum lengths even if there are duplicates can be done by using the max and nchar function as shown in the below examples.Example Live Demox1

Advertisements