ggplot plot, plotting by group across two variables [closed] - r

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a data frame with a patient_name, treatment_status[positive, negative], values
variable = treatment_status
So its something like this should work -
ggplot(data = dat_m, aes(variable, value, group=factor(Patient_Name))) +
geom_jitter(aes(color=factor(variable)))
But unfortunately my patient names don't show up across the x-axis. Is there any way to get this going. Much appreciate any help.

Sounds like you need a interaction function. Try this:
ggplot(data = dat_m, aes(x=interaction(Patient_Name,variable), value) +
geom_jitter(aes(color=factor(variable)))

Related

How is it possible to add 15 to every figure in a column, in a tibble? [duplicate]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I’m new to R and I’m trying to add 15 to every figure in my dataset for a specific column and was wondering how it’s possible to this. Any help would be much appreciated, thanks.
Asssuming you have a data.frame df with a column col that you want to increase:
df$col <- df$col + 15
No loop required, the fundamental objects in R are vectors.

How to order a data.drame with the variables' order in codebook [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
If I have a data.frame that contain the variables that listed in df$Var. Is it a way for me to reorder my data col in the order of df$Var?
The df is looks like this:
Is it a way I can sort dt so the col in dt will in the order of var in df?
Thanks.
We can use factor with levels specified as the values in 'df1$Var'
dt1[order(factor(names(dt1), levels = df1$Var))]
Or use match
dt1[order(match(names(dt1), df1$Var))]

Create new column from two column with logic in R? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
The community is reviewing whether to reopen this question as of 2 years ago.
Improve this question
Looking for other way than ifelse.
How to create NewColumn like this:
As displayed in your picture, you want to paste together two columns. Assuming your dataframe is called df, you can do:
df$NewColumn <- paste(df$Column2,"",df$Column1)
Which will get you the outcome in the picture.

R How to convert data in Matrix? Factor to Integer? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am having trouble operating Matrixs.
First, I want to make factor data to integer so i can operate.
Second, The First col, which shows date, should be factor. How can i change?
Try this:
d <- data.frame(1:10, letters[1:10])
data.matrix(d)
Also you can try this too :
m = matrix(scan("file.csv", what=numeric(), skip=1))
skip=1 to skip a header line.
Hope this will help you

how to plot this function in R [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I know that looks like a silly question but how can I plot this function,
|x|+|y|=z
in 2D by R. I know that is a kind of contour plot but don't know how to manage that.
you can use contour and try this small example
X=seq(-1, 1, length.out=10)
Y=seq(-1, 1, length.out=10)
Z=outer(X, Y, FUN= function(x,y) abs(x)+abs(y))
contour(x=X, y=Y, z=Z)

Resources