Articles on Trending Technologies

Technical articles with clear explanations and examples

How to create bitmap display in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 23-Nov-2020 534 Views

The X Window System is a windowing system for bitmap displays. In R, we can create this graphical display by simply typing x11 in the R console and the graphic interface will pop-up on the right-hand side. We can change the width and height of this display by using the arguments width and height inside x11 call. There are many other arguments of x11 that helps us to change the aesthetic property of the bitmap display. The description of those arguments is as written below:Displaythe display on which the graphics window will appear. The default is to use the value ...

Read More

How to create a boxplot in base R without any axes except Y?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 23-Nov-2020 291 Views

The boxplot function in base R helps us to create the boxplot without any hustle but this plot is covered with a square bracket and also takes the Y-axis labels on left-hand side. We can get rid of this square bracket without making an impact on the Y-axis labels. For this purpose, we need to use frame.plot = FALSE argument inside the boxplot function.Example1> x boxplot(x,frame.plot=FALSE)Output:Example2> y boxplot(y,frame.plot=FALSE)Output:Example3> z boxplot(z,frame.plot=FALSE)Output:

Read More

How to extract variables of an S4 object in R?

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

Suppose we want to create an S4 with defined name data and two numerical columns called by x and y then we can use setClass("data", representation(x1="numeric", x2="numeric")). Now, if we want to extract the variables of this S4 object then we would need to use @ sign instead of $ sign as in a data frame.Example1> setClass("data1", representation(x1="numeric", x2="numeric")) > data1 data1OutputAn object of class "data1" Slot "x1": [1] -0.586187627 0.853689097 -0.602612795 -2.194235741 -1.318522292 [6] -0.984882420 0.273584140 0.364691611 1.025472248 1.198547297 [11] -0.709282551 -0.001441127 -0.201348012 1.296811172 1.520093861 [16] 2.071031215 0.472877022 0.616211695 0.642165615 -0.122773000 Slot "x2": [1] 0.38902289 0.20631450 0.02105516 0.24891420 ...

Read More

How to concatenate two JavaScript objects with plain JavaScript ?

AmitDiwan
AmitDiwan
Updated on 21-Nov-2020 429 Views

Suppose we have two objects defined like this −const obj1 = {    id1: 21,    name1: "Kailash" }; const obj2 = {    id2: 20,    name2: "Shankar" };We are required to write a JavaScript function that takes in two such objects and merges into a single object.In other words, we are required to more or less implement the functionality of Object.assign() function.ExampleThe code for this will be −const obj1 = {    id1: 21,    name1: "Kailash" }; const obj2 = {    id2: 20,    name2: "Shankar" }; const concatObjects = (...sources) => {    const target ...

Read More

How to display star/asterisk sign (*) inside a base R plot?

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

To display characters inside a base R plot we can simply use text function with expression and if we want to display an asterisk then we need to put the asterisk within double quotes. For example, if we want to display three stars then only expression(paste("***"))) should be used. Check out the below examples to understand how it works.Example1> plot(1:10,type="n") > text(8,9,expression(paste(Sig.^"***")))OutputExample2> plot(1:10,type="n") > text(5,6,expression(paste(Less_Sig.^"**")))OutputExample3> plot(1:10,type="n") > text(2,3,expression(paste(Very_Less_Sig.^"**")))Output

Read More

How to make the axes widths in a plot wider than default in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 21-Nov-2020 177 Views

The axes widths are generally very thin in plots but we can make them wider. This will be useful if we want to highlight the axes labels for reasons such as getting attention of the viewer on axes labels etc. To increase the width of the axes in a base R plot, we can use axis function and set the lwd argument.Example> x hist(x) > axis(side=1,lwd=4)Output:Example> axis(side=2,lwd=4)Output:

Read More

How to remove border of bars from histogram in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 21-Nov-2020 945 Views

By default, a histogram drawn in base R has black color borders around bars. We might want to remove these black borders to make the histogram visually smooth. This can be done by using lty argument with the hist function. For example, if we have a vector x and we want to create a histogram of x without border of bars then we can use the argument as hist(x,lty="blank").Example> x hist(x)Output:Creating histogram of x without border of bars:Example> hist(x,lty="blank")Output:

Read More

How to create an S4 object in R?

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

To create an S4 object, we can use setClass function where we will pass the object name, column names, and the type of the data that will be stored in the columns. For example, if we want to create an S4 with name data and two numerical columns called by x and y then we can use setClass("data", representation(x1="numeric", x2="numeric")).Example1> setClass("data1", representation(x1="numeric", x2="numeric")) > data1 data1OutputAn object of class "data1" Slot "x1": [1] -0.586187627 0.853689097 -0.602612795 -2.194235741 -1.318522292 [6] -0.984882420 0.273584140 0.364691611 1.025472248 1.198547297 [11] -0.709282551 -0.001441127 -0.201348012 1.296811172 1.520093861 [16] 2.071031215 0.472877022 0.616211695 0.642165615 -0.122773000 Slot "x2": [1] ...

Read More

How to create a histogram with main title in the outer margin of plot window in base R?

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

The main title of a histogram in base R can be inserted by using title function and if we want to have it in the outer margin then outer argument must be set to TRUE. If the outer argument does not fulfil our requirement then we can use par function to adjust the outer margin area and create the histogram. Check out the below example to understand how it works.Example> x hist(x) > title('Normal Distribution',outer=TRUE)OutputExample> par(oma=c(0,0,2,0)) > hist(x) > title('Normal Distribution',outer=TRUE)Output

Read More

How to find the group-wise median in an R data.table object?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 21-Nov-2020 869 Views

When the assumptions of parametric analysis are not satisfied then we move on to non-parametric analysis and non-parametric analysis often deals with the calculation of median because the data is not normally distributed. If we want to find the group-wise median and the data is stored in a data.table object then lapply function can be used as shown in the below examples.ExampleLoading data.table package:> library(data.table)Consider the below data.table object:Example> Group x1 x2 x3 x4 dt1 dt1OutputGroup x1 x2 x3 x4 1: B 0.515370827 6.174187 542.9350 50.28300 2: B 0.522858146 6.976872 510.5568 49.71331 3: A 1.055456751 3.192242 476.7693 48.88280 4: A ...

Read More
Showing 50921–50930 of 61,297 articles
Advertisements