1

I'm new to Data Science and I just began a new project in R and I got an an Error that I don't know hơw to fix. The column <= 10 automatically changes it's position and stands between column <=1 and column <= 2. How can I fix that?

The Picture is show my error!!!

Phodiem_CK <-
  c(
    Count_nhohonbang1_CK,
    Count_nhohonbang2_CK,
    Count_nhohonbang3_CK,
    Count_nhohonbang4_CK,
    Count_nhohonbang5_CK,
    Count_nhohonbang6_CK
    ,
    Count_nhohonbang7_CK,
    Count_nhohonbang8_CK,
    Count_nhohonbang9_CK,
    Count_nhohonbang10_CK
  )
Phodiem_CK_MT <-
  rbind(
    Count_nhohonbang1_CK,
    Count_nhohonbang2_CK,
    Count_nhohonbang3_CK,
    Count_nhohonbang4_CK,
    Count_nhohonbang5_CK,
    Count_nhohonbang6_CK
    ,
    Count_nhohonbang7_CK,
    Count_nhohonbang8_CK,
    Count_nhohonbang9_CK,
    Count_nhohonbang10_CK
  )
Phodiem_CK_Data <-
  as.data.frame(Phodiem_CK_MT, stringsAsFactors = False)
Phodiem_CK_Data
# bring your data to long format as needed by ggplot
ten_CK <-
  c("<=1",
    "<=2",
    "<=3",
    "<=4",
    "<=5",
    "<=6",
    "<=7",
    "<=8",
    "<=9",
    "<=10")
ggplot(Phodiem_CK_Data, aes(x = ten_CK, , y = Phodiem_CK)) + geom_bar(stat = "identity")
Jan
  • 4,974
  • 3
  • 26
  • 43
  • The column <= 10 is auto change it position and right now it ' s alwayls stand between column <=1 and column <= 2, how can i fix that – Quanghuy Dang Apr 21 '21 at 01:58
  • The code and the screenshot don't show any error. The "# bring your data to long format as needed by ggplot" is a comment. If the issue you bring up in the comment above is part of your question, can you can you please use the `edit` button and add this to the question text. – Till Apr 21 '21 at 03:02

1 Answers1

1

In order to make ggplot respect the order of your vector you need to define it as a factor.

ten_CK <-
    c(
    "<=1",
    "<=2",
    "<=3",
    "<=4",
    "<=5",
    "<=6",
    "<=7",
    "<=8",
    "<=9",
    "<=10"
  )
ten_CK <- factor(ten_CK, levels = ten_CK)
Till
  • 3,845
  • 1
  • 11
  • 18