plot 3 continuous variables against each other in one plot [duplicate] - r

This question already has answers here:
Plot each column against each column
(2 answers)
Plot all pairs of variables in R data frame based on column type [duplicate]
(1 answer)
Closed 17 days ago.
I have the output of 3 different algorithms as a continuous vector. Instead of comparing their correlation 1 by 1, I would like to plot them all simuntaionusly in the same plot, but in different panels. The dataframe looks like this (but contains >10k ids):
df <- data.frame(id=1:5,
feature1=runif(5),
feature2=runif(5,min = 3,max=5),
feature3=runif(5, min = 5,max=8))
Ideally, the resulting plot should looks something like this:
I am fairly sure that there is some simple tidyr function, which expands my dataframe in such a way that I can simply use ggplot2 in combination with facet_grid, but I searched and coudn't find anything..
Any help is much appreciated!

Related

ggplot2 to create boxplots to all columns of a dataset [duplicate]

This question already has answers here:
creating a boxplot for two different column of data frame using ggplot [duplicate]
(2 answers)
Making a ggplot boxplot where each column is it's own boxplot
(2 answers)
Closed 13 days ago.
I have a dataset composed of 10 columns and I want to create a boxplot for each column using ggplot2. They idea is to see if there are outliers in any column
I know how to use to the package to create a boxplot for each column individually but I would like to know if it is possible to make it directly to all columns of the data set

How can i separate categorical data from continuous data in a dataset in R? [duplicate]

This question already has answers here:
Selecting only numeric columns from a data frame
(12 answers)
Closed 1 year ago.
I have a dataset and I need to plot histograms for all the continuous data which i know how to do, however I cant use a loop as there are categorical columns too, meaning histograms wont be created for them which will create an error. Is there a way to separate the continuous data from the categorical data? If worse comes to worst, I can just manually remove the categorical features however I would like to know if theres a way to do this automatically for future reference.
You can use package "dplyr", and in the example below, you chose all columns with factor variables
data <- data %>%
select_if(is.factor)

How to remove value from a plot on R [duplicate]

This question already has answers here:
Boxplot sees values that aren't there
(1 answer)
How to remove ticks and labels of dropped off factors in a box plot
(1 answer)
Closed 5 years ago.
You can see my plot in this link.
I want to remove the first three points from the x axis, so I only display data from "2.31-52k", "1.52-100k", "3.18-31k", "4.<18k", "0.>100k". And not -1.0,-3.1 etc.
I have managed to remove the data to produce this graph, by creating a subset in dAll$income and assigning it to a new data frame with the following code.
new_df = subset(dAll, subset = dAll$income %in% c("2.31-52k", "1.52-100k", "3.18-31k", "4.<18k", "0.>100k"))
However when I plot this, the values remain on the x axis.

Categorising data within a range in R [duplicate]

This question already has answers here:
Convert continuous numeric values to discrete categories defined by intervals
(2 answers)
Closed 6 years ago.
I have a data frame in R that has a personal ID, an income and some other variables. I would like to add a new column to this data that categorises people in to which income group they fit in to (0-24,999, 25,000-49,999, 50,000-74,999, 75000-99,000, etc).
I then want to be able to make frequency tables of this data compared with some of the other variables (eg: weekly hours worked, age).
I should be fine to figure out the latter of these problems, but I am having trouble figuring out how to categorise my data. Any help would be greatly appreciated.
Thank you.
We can use cut or findInterval to group the "Variable"
gr <- cut(df1$Variable, breaks = c(0, 24999, 49999,74999,99999, Inf))
Then, use table to get the frequency count
table(gr, df1$age)

How to clean/reconstruct factor in R [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
dropping factor levels in a subsetted data frame in R
I have a data frame which has a factor column, then I would like to use subset to extract only part of its data. But the extracted data frame's factor column still has the same levels even some levels has no value. This would impact my following actions (like visualization using ggplot).
The following is a sample code.
d<-data.frame(c1=factor(c(1,1,2,3)),c2=c("a","b","c","d"))
d<-subset(d,c1 %in% c(1,2))
d$c1
The column c1 still have 3 levels (1,2,3), but actually I'd like to it to be (1,2), because these's no value for level 3. Then in visualization, I won't draw any graph for level 3.
How can I achieve that ? Thanks
Use droplevels:
d <- droplevels(d)

Resources