I am new to R and I (probably) have a simple question, but I am unable to get my head around it. Even though I have been trying it in multiple ways:
I want to make a plot from a subgroup of a certain classification (aneurysm type) as follows:
ggplot(df, aes(x= MSS, y= Aneurysm_Volume)) +
geom_point(aes(x = df$TF1_months, y = df$AV1[df$xaneurysm_type == 1])) +
geom_point(aes(x = df$TF2_months, y = df$AV2[df$xaneurysm_type == 1])) +
geom_point(aes(x = df$TF3_months, y = df$AV3[df$xaneurysm_type == 1])) +
geom_point(aes(x = df$TF4_months, y = df$AV4[df$xaneurysm_type == 1])) +
geom_point(aes(x = df$TF5_months, y = df$AV5[df$xaneurysm_type == 1])) +
xlim(0, NA) + ylim(0, NA)
However, the following error applies. Error: Aesthetics must be either length 1 or the same as the data (154): y
I tried to make a seperate variably for Y as follows:
if(df$xaneurysm_type == 1) {
(df$juxtavolume1 = df$AV1)
} else {
(df$juxtavolume1 = NA)
}
However, the following warning applies:
Warning message: In if (df$xaneurysm_type == 1) { : the condition has length > 1 and only the first element will be used
I have also tried to make the conditional variable the following way:
df$juxtavolume1 <- as.integer(NA)
df[which(df$xaneurysm_type == 1),]$juxtavolume1 <- as.integer(df$AV1)
But then the following error applies:
Error in $<-.data.frame
(*tmp*
, juxtavolume1, value = c(NA_integer_, :
replacement has 154 rows, data has 97
Does anybody understand where I am going wrong? Your help is much appreciated!
Warm regards