Found 26504 Articles for Server Side Programming

How to display raise to the power on X-axis in base R plot?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 06:25:13

403 Views

To display anything different than the vector or column names on the axes, we need to use xlab for X-axis and ylab for Y-axis. Therefore, if we want to display raise to the power on X-axis then xlab argument will be along with the plot function. For example, if we have a vector called x and we want to create a point chart for x -square with X-axis showing x^2 then it can be done as plot(x^2,xlab="x^2").Example> x y plot(x,y)OutputExample> plot(x/1000,y,xlab="x/10^3")Output

How to create bar plot with log values using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 06:23:39

1K+ Views

To create the bar plot using ggplot2, we simply need to use geom_bar function and if we want to have the log scale of y variable then it can be set with aes under geom_bar. For example, if we have a data frame called df that contains a categorical column x and a numerical column y then the bar plot with log of y can be created by using the below command −ggplot(df, aes(x, y))+geom_bar(stat="identity", aes(y=log(y)))ExampleConsider the below data frame −Live Demo> x y df dfOutput   x     y 1 S1 53347 2 S2 84208 3 S3 12140 4 ... Read More

How to find the significant correlation in an R data frame?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 06:23:21

585 Views

To find the significant correlation in an R data frame, we would need to find the matrix of p-values for the correlation test. This can be done by using the function rcorr of Hmisc package and read the output as matrix. For example, if we have a data frame called df then the correlation matrix with p-values can be found by using rcorr(as.matrix(df)).Example1Consider the below data frame −Live Demo> x1 x2 x3 df1 df1Output            x1          x2          x3 1  -0.96730523 -1.73067540 -0.01974065 2   0.08564529 -0.05200856  0.76356487 3 ... Read More

How to get the colour name from colour code in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 06:22:31

570 Views

To get the color name from color code, we can use the color_id function of plotrix package. If we have a vector of colour codes say x then the colour name can be found by using the command sapply(x, color.id).ExampleLive Demo> x xOutput[1] "#FF0000" "#FF1F00" "#FF3D00" "#FF5C00" "#FF7A00" "#FF9900" "#FFB800" [8] "#FFD600" "#FFF500" "#EBFF00" "#CCFF00" "#ADFF00" "#8FFF00" "#70FF00" [15] "#52FF00" "#33FF00" "#14FF00" "#00FF0A" "#00FF29" "#00FF47" "#00FF66" [22] "#00FF85" "#00FFA3" "#00FFC2" "#00FFE0" "#00FFFF" "#00E0FF" "#00C2FF" [29] "#00A3FF" "#0085FF" "#0066FF" "#0047FF" "#0029FF" "#000AFF" "#1400FF" [36] "#3300FF" "#5200FF" "#7000FF" "#8F00FF" "#AD00FF" "#CC00FF" "#EB00FF" [43] "#FF00F5" "#FF00D6" "#FF00B8" "#FF0099" "#FF007A" "#FF005C" "#FF003D" [50] "#FF001F"Loading ... Read More

How to extract unique combination of rows in an R data frame?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 06:20:12

849 Views

To extract the unique combination of rows, we can subset the data frame with single square brackets and use the negation of the duplicated function after sorting the rows in the data frame. The sorting of the data frame can be done with the help of apply function and we will have to transpose the sorting as shown in the below examples. To understand how it works, do it in parts.Example1Consider the below data frame −Live Demo> x1 x2 df1 df1Output   x1 x2 1   3  1 2   1  0 3   1  0 4   1  3 5 ... Read More

How to find the row sum for each column by row name in an R matrix?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 06:19:52

2K+ Views

To find the row sum for each column by row name, we can use rowsum function. For example, if we have a matrix called M then the row sums for each column with row names can be calculated by using the command rowsum(M, row.names(M)).Example1Live Demo> M1 rownames(M1) colnames(M1) M1Output       V1 V2 Male    3  6 Female  6  5 Female  7  3 Female  2  5 Female  5  3 Female  4  4 Female  1  4 Female  4  4 Female  7  5 Male    2  5 Female  5  5 Male    7  1 Female  5  6 Male    6  5 Female ... Read More

How to change the legend title in ggplot2 in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 06:19:33

473 Views

In ggplot2, by default the legend title is the title of the grouping column of the data frame. If we want to change that title then scale_color_discrete function. For example, if we have a data frame called df that contains two numerical columns x and y and one grouping column say group then the scatterplot with a different legend title can be created by using the below command −ggplot(df, aes(x, y, color=group))+geom_point()+scale_color_discrete("Gender")ExampleConsider the below data frame −Live Demo> x y grp df dfOutput             x          y    grp 1  -2.27846496  0.8121008   ... Read More

What is an inline function in C language?

Bhanu Priya
Updated on 13-Dec-2024 13:03:49

14K+ Views

Inline Function An inline function in C reduces function calls by expanding the function's code at the call site during compile time. This increases the efficiency of the function. The inline function can be substituted at the point of the function call, but this substitution is always the compiler's choice. In an inline function, the function call is replaced by the actual program code. Most Inline functions are ... Read More

What are the Pre-processor Commands in C language?

Bhanu Priya
Updated on 08-Mar-2021 06:14:36

4K+ Views

The preprocessor is a program that sends the source code before it passes through the compiler. It operates under preprocessor directives which begin with the symbol #.TypesThe three types of preprocessor commands are as follows −Macro substitution directives.File inclusion directives.Compiler control directives.Macro substitution directivesIt replaces every occurrence of an identifier by a predefined string.The syntax for defining a macro substitution directive is as follows −# define identifier stringFor example, #define    PI    3.1415 #define    f(x)  x *x #undef     PIExampleFollowing is the C program for the macro substitution directive −#define wait getch( ) main ( ){   ... Read More

Explain the constant type qualifier in C language

Bhanu Priya
Updated on 08-Mar-2021 06:10:16

229 Views

Type qualifiers add special attributes to existing datatypes in C programming language.There are three type qualifiers in C language and constant type qualifier is explained below −ConstThere are three types of constants, which are as follows −Literal constantsDefined constantsMemory constantsLiteral constants − These are the unnamed constants that are used to specify data.For example, a=b+7 //Here ‘7’ is literal constant.Defined constants − These constants use the preprocessor command ‘define" with #For example, #define PI 3.1415Memory constants − These constants use ‘C’ qualifier ‘const’, which indicates that the data cannot be changed.The syntax is as follows −const type identifier = valueFor ... Read More

Advertisements