Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 125 of 196

How to create bar plot with gradient colors using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 6K+ Views

To create bar plot with gradient colors using ggplot2, we can use scale_fill_gradient function where we can set the lower and higher color values.For Example, if we have a data frame called df that contains two columns say Cat and Count then we can create the bar plot with gradient colors by using the below command −ggplot(df,aes(Cat,Count,fill=Cat))+geom_bar(stat="identity")+scale_fill_gradient(low="blue",high="red")ExampleFollowing snippet creates a sample data frame −x

Read More

Create ggplot2 graph with darker axes labels, lines and titles in R

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 816 Views

To create a ggplot2 graph with darker axes labels, darker lines, and dark titles, we can use theme_classic function of ggplot2 package with base_size argument set to a larger value.For Example, if we have a data frame called df that contains two columns say x and y then we can create the scatterplot between x and y using ggplot2 with darker axes labels, darker lines, and dark titles by using the below command −ggplot(df,aes(x,y))+geom_point()+theme_classic(base_size=22)ExampleFollowing snippet creates a sample data frame −x

Read More

Create multiple regression lines in a single plot using ggplot2 in R.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 10K+ Views

To create multiple regression lines in a single plot using ggplot2, we can use geom_jitter function along with geom_smooth function. The geom_smooth function will help us to different regression line with different colors and geom_jitter will differentiate the points.Check out the below Example to understand how it can be done.ExampleFollowing snippet creates a sample data frame −x1

Read More

Create a graph without background panel using ggplot2 in R.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 208 Views

To create a graph without background panel, we can use theme function of ggplot2 package where we can set panel.background argument to blank.For Example, if we have a data frame called df that contains two columns say x and y then we can create scatterplot between x and y without background panel using ggplot2 by using the below command −ggplot(df,aes(x,y))+geom_point()+theme(panel.background=element_blank())ExampleConsider the below data frame −x

Read More

Create a graph using ggplot2 without axes ticks and axes labels.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 242 Views

To create a graph using ggplot2 without axes ticks and axes labels, we can use theme function where we can use set axes ticks and axis labels to blank with the help of arguments corresponding to each axes such as axis.ticks.x, axis.ticks.y, axis.text.x, and axis.text.y.To understand how it works, check out the below Example.ExampleConsider the below data frame −x

Read More

How to display a variable with subscript ggplot2 graph in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 1K+ Views

Sometimes we have variables that have a subscript associated with them. This subscript is used to define the characteristics of the variable or to differentiate similar variables from each other.In this type of situation, displaying a variable with subscript in a graph created with the help of ggplot2 can be done by using the geom_text function. Check out the below Example to understand how it can be done.ExampleConsider the below data frame −x1

Read More

How to display tilde ggplot2 graph in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 478 Views

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

Read More

How to create a 90-degree arc in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 346 Views

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

How to create a circle with different color border in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 574 Views

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

How to fill bars of a bar plot created using ggplot2 with colors based on frequency?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 12-Nov-2021 897 Views

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

Read More
Showing 1241–1250 of 1,958 articles
« Prev 1 123 124 125 126 127 196 Next »
Advertisements