简体   繁体   中英

How to plot a Spearman correlation with type double

I am trying to plot the Spearman correlation between two highly correlated variables but I am getting a type "Double" error.

Error - 'pairlist' object cannot be coerced to type 'double' when trying to ploy spearman correlation between two variables

I have subsetted the data, converted the two columns to numeric data and tried to convert the data frame to a matrix but I am still getting the same error.

   library(ggpubr)
var_sub_set <- as.data.frame(bc_data[ ,c("compactness_mean", "points_mean" )])


Var <- as.data.frame(sapply(var_sub_set, as.numeric))

ggscatter(Var, x = "compactness_mean", y = "points_mean", 
          add = "reg.line", conf.int = TRUE, 
          cor.coef = TRUE, cor.method = "spearman",
          xlab = "Compactness Mean", ylab = "Points Mean")

The data should be plotted on a scatterplot and show the p_value and any linear lines.

dput sample output

structure(list(compactness_mean = c(0.06981, 0.1147, 0.07804, 
0.1136, 0.06934, 0.07722, 0.1021, 0.1768, 0.08578, 0.09097, 0.1644, 
0.06679, 0.1089, 0.03789, 0.09871, 0.133, 0.09462, 0.07664, 0.1838, 
0.01781, 0.04304, 0.02749, 0.01867, 0.01471, 0.08543, 0.0444, 
0.02068, 0.1562, 0.02069, 0.063, 0.02583, 0.0226, 0.05598, 0.01692, 
0.01737, 0.034, 0.0287, 0.02037, 0.03263, 0.06495, 0.1255)), .Names = c("compactness_mean", 
"points_mean"), row.names = c(NA, -569L), class = "data.frame")

Code was correct. reinstalling ggplot2 and ggpubr fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM