Unsplit a Split Data Table Object in R

Nizamuddin Siddiqui
Updated on 12-Nov-2021 05:33:26

314 Views

To unsplit a split data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, use split function to split the data.table object.After that, use do.call function along with rbind function unsplit the data frame.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) Grp

Standardize Multiple Columns in Data Table Object in R

Nizamuddin Siddiqui
Updated on 12-Nov-2021 05:27:52

300 Views

To standardize multiple columns not all in data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, subset the columns with single square brackets and use lapply, list and scale function to standardize those columns.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) x

Create ggplot2 Graph with Reversed Y-Axis and X-Axis on Top in R

Nizamuddin Siddiqui
Updated on 12-Nov-2021 04:08:58

1K+ Views

To create ggplot2 graph with reversed Y-axis and X-axis on top, we can use scale_y_reverse and scale_x_continuous function of ggplot2 package.For Example, if we have a data frame called df that contains two columns say X and Y and we want to create the scatterplot between X and Y with reversed Y-axis and X-axis on top then we can use the below command −ggplot(df,aes(X,Y))+geom_point()+scale_y_reverse()+scale_x_continuous(position="top")ExampleFollowing snippet creates a sample data frame −x

Create Correlation Matrix Plot Without Variable Labels in R

Nizamuddin Siddiqui
Updated on 12-Nov-2021 04:06:03

545 Views

To create correlation matrix plot without variables labels in R, we can use tl.pos argument set to n.For Example, if we have a correlation matrix say M then we can create the correlation matrix plot without variables labels by using the below command −corrplot(M,tl.pos='n')ExampleFollowing snippet creates a sample data frame −x

Create Bar Plot with Gradient Colors Using ggplot2 in R

Nizamuddin Siddiqui
Updated on 12-Nov-2021 04:01:29

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

Create ggplot2 Graph with Darker Axes, Labels, Lines and Titles in R

Nizamuddin Siddiqui
Updated on 12-Nov-2021 04:00:20

783 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

Create Multiple Regression Lines in a Single Plot Using ggplot2 in R

Nizamuddin Siddiqui
Updated on 12-Nov-2021 03:52:33

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

Create a Graph Without Background Panel Using ggplot2 in R

Nizamuddin Siddiqui
Updated on 12-Nov-2021 03:45:36

188 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

Create a Graph Using ggplot2 Without Axes Ticks and Labels

Nizamuddin Siddiqui
Updated on 12-Nov-2021 03:44:32

211 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

Display Variable with Subscript in ggplot2 Graph in R

Nizamuddin Siddiqui
Updated on 12-Nov-2021 03:43:22

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

Advertisements