Plot a character vector against a numeric vector in R

后端 未结 1 693
无人及你
无人及你 2020-12-06 03:25

I have the following data frame in R:

>AcceptData
  Mean.Rank Sentence.Type
1       2.5       An+Sp+a
2       2.6      An+Nsp+a
3       2.1       An+Sp-a         


        
1条回答
  •  被撕碎了的回忆
    2020-12-06 04:05

    The default plot function has a method that allows you to plot factors on the x-axis, but to use this, you have to convert your text data to a factor:

    Here is an example:

    x <- letters[1:5]
    y <- runif(5, 0, 5)
    
    plot(factor(x), y)
    

    enter image description here

    And with your sample data:

    AcceptData <- read.table(text="
    Mean.Rank Sentence.Type
    1       2.5       An+Sp+a
    2       2.6      An+Nsp+a
    3       2.1       An+Sp-a
    4       3.1      An+Nsp-a
    5       2.4       In+Sp+a
    6       1.7      In+Nsp+a
    7       3.1       In+Sp-a
    8       3.0      In+Nsp-a", stringsAsFactors=FALSE)
    
    plot(Mean.Rank~factor(Sentence.Type), AcceptData, las=2, 
         xlab="", main="Mean Acceptability Ranking per Sentence")
    

    enter image description here

    0 讨论(0)
提交回复
热议问题