r - Why does ordering by factor destroy the decimal places -
i try simple ggplot of dataframe
structure(list(clevel = c(3, 4, 5, 6, 7, 8, 9, 10, 11), sensitivity = structure(c(1l, 2l, 3l, 3l, 5l, 5l, 7l, 8l, 9l), .label = c("56.6666666666667","53.125", "52.9411764705882", "52.9411764705882", "54.2857142857143", "54.2857142857143", "55.5555555555556", "56.7567567567568", "57.1428571428571"), class = "factor"), specificity = c(76.4705882352941, 76.4705882352941, 76.4705882352941, 76.4705882352941, 76.4705882352941, 76.4705882352941, 76.4705882352941, 76.4705882352941, 76.4705882352941)), .names = c("clevel", "sensitivity", "specificity"), row.names = c(na, -9l), class ="data.frame")
when plot follows
library(ggplot2) ggplot() + geom_point(aes(clevel, sensitivity, color = "red",size=12), st) + geom_point(shape=5)
i x axis not ordered way want.
so tried
st$sensitivity <- factor(st$sensitivity, levels = st$sensitivity[order(st$clevel)])
but error
in `levels<-`(`*tmp*`, value = if (nl == nl) as.character(labels) else paste0(labels, : duplicated levels in factors deprecated
so looked @ data frame again , looks though there duplicates in sensitivity column because decimal point has been stripped off of numbers same. want order x axis seems unnecessarily complicated. how can this?
if change sensitivity double, resulting plot looks appropriate:
st <- structure(list(clevel = c(3, 4, 5, 6, 7, 8, 9, 10, 11), sensitivity = c(56.6666666666667, 53.125, 52.9411764705882, 52.9411764705882, 54.2857142857143, 54.2857142857143, 55.5555555555556, 56.7567567567568, 57.1428571428571 ), specificity = c(76.4705882352941, 76.4705882352941, 76.4705882352941, 76.4705882352941, 76.4705882352941, 76.4705882352941, 76.4705882352941, 76.4705882352941, 76.4705882352941)), .names = c("clevel", "sensitivity", "specificity"), row.names = c(na, -9l), class = "data.frame") library(ggplot2) ggplot() + geom_point(aes(clevel, sensitivity, color = "red",size=12), st) + geom_point(shape=5)
Comments
Post a Comment