![]() ![]() Originally, I didn't use the group argument at all, but then it wasn't drawing the lines at all and I couldn't figure out why. Oh also, the ggplot is jacked up because you told it all the data should be in the same group group = 1, overriding the grouping that colour = Continent would have done correctly. It still doesn't like right though, for the same reason the ggplot one doesn't look right. That looks a lot more like what ggplot did. Thanks for the suggestion! I changed the data argument of plot_ly to data = arrange(rugby_data, DebutYear) and now I have this plot: Reorder rugby_data in order of DebutYear and see if that works Looks like plot_ly it did the equivalent of geom_path() instead of geom_line(), instead of drawing lines in the order of the variable mapped to x axis, it drew lines in the order of the rows. Mutate(Continent = case_when(team %in% Americas ~ "Americas", Oceania = c("Australia", "Fiji", "New Zealand", "Samoa", "Tonga") This is the code I used to add it: rugby_data = na.omit(rugby_data)Īmericas = c("Canada", "USA", "Argentina", "Uruguay")Įurope = c("England", "France", "Ireland", "Italy", "Romania", "Scotland", "Wales") Like, why is it connecting the points like that? I can tell it's grouping the data by continent, like it should be, but why didn't it just do 5 separate lines like plot_ly did? And why did it connect the points in such a weird way, with all those pieces on the outside? That's not how you'd normally connect the dots in a line plot.Įdit: The "Continent" column of rugby_data was added in an earlier question in the assignment. That's less chaotic looking than what plot_ly did, but it still doesn't make a lot of sense. Geom_line(aes(color = Continent )) + geom_point(aes(color = Continent)) Labs(title = "Count of Rugby Players vs Debut Year, Grouped by Team Continent", Ggplot(aes(x = DebutYear, y = n, group = 1)) + I tried using ggplot instead like this: LinePlot = rugby_data %>% What the heck did I do wrong in my code to get such a crazy plot? I've been looking at tutorials and as far as I can tell I followed them, so I don't get why my result is so weird. It looks like it went back and forth between the same points multiple times which is definitely not how a line plot is supposed to be made. I don't understand why it connected the points like that. Layout(title = PlotTitle, xaxis = x_axis, yaxis = y_axis) %>%Īnd got this crazy looking plot which isn't exactly useful for visualizing the data: Type = "scatter", mode = 'lines + markers' ) %>% LinePlot = plot_ly(data = rugby_data, x = ~DebutYear, y = ~n, Rugby_data = ungroup(rugby_data) #ungroup to avoid lines being invisible Y_axis = list(title = "Player Count", font = "Modern Family Roman") X_axis = list(title = "Debut Year", font = "Modern Family Roman") Y = 0.95, x = 0.5, font = "Modern Family Roman") I grouped the data like this to add the n variable to the dataframe: DebutYear = format(rugby_data$debut, "%Y")Īnd then I plotted the data with plot_ly like this: PlotTitle = list(text = "Count of Rugby Players vs Debut Year, Grouped by Team Continent", Plus, the plot_ly and ggplot2 functions give very different results and I don't understand why. I was able to add the n column to the dataframe and make the lineplots, but the results are really weird and I don't understand how to interpret them. ![]() Include a discussion on how the new variable was created and anything you observe in the visualization. Your graph should have 5 lines, colorized by continent, formatted with x- and y-axis labels and a title. Using a line plot, visualize this new variable. We have this dataset on rugby players and the question I'm on says,Ĭreate a new variable, in the `rugby_data` dataframe, called `n` that calculates the count of the number of players per debut year per continent. So I'm learning R as part of a data science class and the assignment this week is all about ggplot2 and plotly and I'm rather flummuxed at some results I got while plotting data. ![]()
0 Comments
Leave a Reply. |