Found 33676 Articles for Programming

How to change the color of line in xyplot in R?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 08:22:10

532 Views

To change the color of line in xyplot, we can use col argument.For example, if we have two vectors say X and Y and we want to create a red colored xyplot between X and Y then we can use the following command −xyplot(x~y,type="l", col="red")Check out the below example to understand how it works.ExampleTo change the color of line in xyplot, use the code given below −set.seed(123) library(lattice) xyplot(1:5~rpois(5,5),type="l",col="blue")OutputIf you execute the above given code, it generates the following output −

How to fill the outliers with different color in base R boxplot?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 08:21:09

2K+ Views

To fill the outliers in boxplot with different color in base R, we can use outpch argument for the shape and outbg argument for colors.For example, if we have a vector called X that contains some outliers then we can create a boxplot of X with different color outliers by using the below mentioned command −boxplot(X,outpch=21,outbg="blue")ExampleTo fill the outliers in boxplot with different color in base R, use the code given below −x

How to display outliers in boxplot with different shape in base R?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 08:19:41

703 Views

To display outliers in boxplot with different shape in base R, we can use outpch argument in boxplot.For example, if we have a vector called X that contains some outliers then we can create a boxplot of X with different shape of outliers by using the below given command −boxplot(X,outpch=17)ExampleTo display outliers in boxplot with different shape in base R, use the code given below −x

How to change the color of box of boxplot in base R?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 08:18:04

13K+ Views

To change the color of box of boxplot in base R, we can use col argument inside boxplot function.For example, if we have a vector called V and we want to create a boxplot of V without red colored box then we can use the following command −boxplot(x,col="red")ExampleTo change the color of box of boxplot in base R, use the code given below −x

How to change the color of outliers in base R boxplot?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 08:16:26

2K+ Views

To change the color of outliers in base R boxplot, we can use outcol argument in boxplot function.For example, if we have a vector called X that contains some outliers then we can create a boxplot of X with blue color outliers by using the below given command −boxplot(X,outcol="red")ExampleTo change the color of outliers in base R boxplot, use the code given below: −x

How to write plot description outside plot in facetted plot using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 08:14:29

579 Views

To write plot description outside plot using ggplot2, we can use annotate function and coord_cartesian function. The annotate function will define the plot description and the coord_cartesian function will define the position of the text outside the plot area.Check out the below given example to understand how it works.ExampleFollowing snippet creates a sample data frame −x

How to test if strings stored in a vector are present in an R list?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 08:11:43

153 Views

To test if strings stored in a vector are present in an R list or not, we can use mapply function. For example, if we have a vector of strings say V and a list called LIST then we can check whether elements in V are present in LIST by using the following command − mapply(`%in%`,V,LIST)Example 1Following snippet creates a vector and list −x

Find the frequency of successive occurrences less than equal to a threshold in an R data frame column?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 08:09:28

277 Views

To find the frequency of successive occurrences less than a threshold value in an R data frame column, we can use rle function along with sum function.Check out the below given examples to understand how it can be done.Example 1Following snippet creates a sample data frame −x

How to find numbers that are divisible by a certain number for a range of values in R?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 07:53:15

3K+ Views

In R, the divisibility of a number by a certain number can be found by using the modulus operator %%. If we want to check the divisibility of a set of numbers by a certain number then for loop will be used.Check out the below given examples to understand how it can be done.Example 1To check which numbers between 1 and 100 are divisible by 10, use the following code −for(x in 1:100){    + if(x%%10==0){          + print(x)    + } + }If you execute the above given code, it generates the following output −[1]  10 ... Read More

How to create a scatterplot with white background and no gridlines using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 07:45:48

363 Views

Practically, the scatterplots are well visualized on white background just like on white paper. If we want to create a scatterplot with white background and without gridlines using ggplot2 then we can apply classic theme to the plot.Check out the below given example to understand how it can be done.ExampleFollowing snippet creates a sample data frame −x

Advertisements