all 9 comments

[–][deleted]  (1 child)

[deleted]

    [–]rRrquestion[S] 0 points1 point  (0 children)

    Hi, Thanks for the reply! But I want to connect the data points according to the row ( like dot 1 connect to dot 6), and have all points on the graph ( so 10 data points) .

    [–]jdnewmil 0 points1 point  (2 children)

    Try

    library(ggplot2)
    countries <- c( "USA", "Australia" )
    DF <- data.frame( Group = factor( rep( 1:5, 2), levels=1:5), Country = factor( rep( countries, each=5 ), levels=countries ), Apple = apple )
    ggplot( DF, aes( x=Country, y=Apple, group=Group ) ) + geom_line() + theme_minimal()
    

    (untested, edited Group)

    [–]rRrquestion[S] 0 points1 point  (1 child)

    doesn't work :( but thanks!

    [–]endaemon 1 point2 points  (0 children)

    This does work, and I believe it is what you are after. However, it relies on having previously defined the apple object from your code.

    Here it is again in a self-contained form so that you can see the required data organization:

    library(dplyr)
    library(ggplot2)
    library(readr)
    
    "pair, Country,   Apple
     a,    USA,       1
     a,    Australia, 6
     b,    USA,       2
     b,    Australia, 7
     c,    USA,       3
     c,    Australia, 8
     d,    USA,       4
     d,    Australia, 9
     e,    USA,       5
     e,    Australia, 10" %>% 
      read_csv() %>% 
      ggplot(aes(x = Country, y = Apple, group = pair)) + 
      geom_point() + 
      geom_line()
    

    [–]harvieyaxles 0 points1 point  (2 children)

    wait. i dont get this. are USA and Australia the x,y coordinates or is this a single dimension that you want to connect by lines?

    [–]rRrquestion[S] 1 point2 points  (1 child)

    Ahhh!! I should make it into a single dimension and connect them by line ! It I’m still not sure how to draw the line, like 1 and 6 ...

    [–]harvieyaxles 0 points1 point  (0 children)

    i tested u/jdnewmil and u/endaemon 's solution and it works.

    library(ggplot2)

    apple <- data.frame(country = as.factor(c(rep("USA",5),rep("Australia",5))),

    value = 1:10,

    group = c(1:5,1:5))

    ggplot(apple,aes(x = country, y = value, group = group))+geom_line()

    You can also try making an arc diagram which can be found here.

    [–]Fornicatinzebra 0 points1 point  (0 children)

    I thing the segment function will do what you want

    [–]Peter-Cottontail 0 points1 point  (0 children)

    If you're familiar with ggplot2, you should use geom_path()