Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 123 of 196

How to remove ticks in a plot created by using gglot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 07-Nov-2020 258 Views

In a plot created by using ggplot2, the axes values are generated with tick marks such as representing X-axis labels from 1 to 10 and Y-axis labels from 10 to 1 but we can get rid of this tick marks by using theme function. If we want to create a plot without ticks then we just need to add the following code to the plot code.theme(axis.ticks.x=element_blank(), axis.ticks.y=element_blank())ExampleConsider the below data frame.Live Demo> set.seed(321) > x y df dfOutputx y 1 1.0426226 6.238295 2 0.9821990 4.855467 3 0.9930504 6.334253 4 0.9970088 3.552478 5 0.9969010 3.976679 6 1.0067046 5.128251 7 1.0181710 1.853243 ...

Read More

How to combine two columns of a data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 07-Nov-2020 3K+ Views

A data.table object is almost same as a data frame. To combine two columns of a data.table object, we can use paste0 function. For example, if we have a data frame defined as DT that contains two columns named as x and y then we can combine them using the below command.DT[, xy:=paste0(x, y)]ExampleLoading data.table package.> library(data.table)Consider the below data.table object.Example> x y dt1 dt1Outputx y 1: 1 a 2: 2 b 3: 3 c 4: 4 d 5: 5 e 6: 6 f 7: 7 g 8: 8 h 9: 9 i 10: 10 j 11: 11 k 12: ...

Read More

How to create an arrow in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 07-Nov-2020 2K+ Views

To create an arrow R, we can use plot function and arrows function. We just need to understand all the coordinate values that should be passed inside the arrows function. For example, if we have two vectors that contains values from 1 to 10 then the arrow can be created by using arrows function as arrows(1,1,10,10).ExampleLive Demo> x y plot(x,y)OutputExample> arrows(1,1,10,10)Output

Read More

How to check whether a column value is less than or greater than a certain value in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 07-Nov-2020 2K+ Views

To check whether a column value is less than or greater than a certain value, we can use with function and the output will be a logical vector representing values with TRUE when the condition is satisfied and FALSE when the condition is not satisfied. For example, if we have a column say x of an R data frame df and we want to check whether any of the values in x is greater than 10 or not then it can be done by using with(df, df$x>10).ExampleConsider the below data frame:Live Demo> set.seed(1002) > x1 y1 z1 df1 df1Outputx1 y1 ...

Read More

How to extract a data.table row as a vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 07-Nov-2020 2K+ Views

A data.table object is similar to a data frame object but there are few things that can be specifically applied to a data.table because data.table package functions was defined for a data.table object only. If we want to extract a data.table row as a vector then we can use as.vector function along with as.matrix so that the as.vector can read the row properly.Loading data.table package:> library(data.table)Consider the below vectors and create a data.table object:Example> x1 x2 x3 x4 x5 DT1 DT1Outputx1 x2 x3 x4 x5 1: B C C D E 2: B C D B E 3: B C ...

Read More

How to create a hierarchical cluster dendrogram in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 07-Nov-2020 425 Views

A dendrogram display the hierarchical relationship between objects and it is created by using hierarchical clustering. In base R, we can use hclust function to create the clusters and the plot function can be used to create the dendrogram. For example, if we want to create the dendrogram for mtcars data then it can be done as shown below:> hc=hclust(dist(mtcars)) > plot(hc)Example1Live Demo> head(mtcars)Outputmpg cyl disp hp drat wt qsec vs am gear carb Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 ...

Read More

How to create a row sum and a row product column in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 07-Nov-2020 472 Views

To create a row sum and a row product column in an R data frame, we can use rowSums function and the star sign (*) for the product of column values inside the transform function. For example, if we have a data frame df that contains x, y, z then the column of row sums and row product can be created as:transform(df, RowSums=rowSums(df), RowProducts=x*y*z)ExampleConsider the below data frame:Live Demo> set.seed(3251) > x1 y1 z1 a1 b1 df1 df1Outputx1 y1 z1 a1 b1 1 2 4 10 10 5 2 0 9 5 5 8 3 4 7 6 12 9 ...

Read More

How to create an exponential curve in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 07-Nov-2020 7K+ Views

To create an exponential curve, we can use exp function inside the plot function for the variable that we want to plot. For example, if we have a vector x then the exponential curve for the vector x can be created by using plot(x,exp(x)). We can use the exponential function for the variable that is appropriate based on the objective of the analysis, here we have shown only an example of how it works.Example1Live Demo> x plot(x,exp(x))OutputExample2Live Demo> y plot(y,exp(y))Output

Read More

How to create a staircase plot in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 07-Nov-2020 657 Views

The simple staircase plot can be created by using geom_tile function of ggplot2 package. We just need to use the vector or the column for which we want to create the staircase plot in place of x and y as well. For example, if we have a column say x of an R data frame df then the staircase plot can be created as ggplot(df, aes(x, x))+geom_tile().ExampleConsider the below data frame:Live Demo> x df dfOutputx 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10Loading ggplot2 package and creating staircase ...

Read More

How to create colored barplot using ggplot2 without legend entries in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 07-Nov-2020 163 Views

When we create a colored barplot using ggplot2 the legend entries are automatically created. If we want to create the plot without those legend entries then theme function can be used. For example, if we have a data frame df that contains x as categorical variable and y as count variable then barplot without legend entries can be created as:ggplot(df, aes(x, y, fill=x))+geom_bar(stat="identity")+theme(legend.position="none")ExampleConsider the below data frame:Live Demo> x y df dfOutputx y 1 A 24 2 B 28 3 C 25 4 D 27 5 E 26Loading ggplot2 package and creating the barplot:> library(ggplot2) > ggplot(df, aes(x, y, fill=x))+geom_bar(stat="identity")Output:Creating ...

Read More
Showing 1221–1230 of 1,958 articles
« Prev 1 121 122 123 124 125 196 Next »
Advertisements