1
votes

I calculated following data frame of maximimum response time of a server with pre-defined number of simultaneous connections:

> print(summary_data)    
    max     no_of_threads
    1.1801799   10
    1.0883594   20
    0.9556356   30
    0.9130625   40
    3.2130118   50
    1.1573432   60

When I plot this dataframe with ggplot using geom_bars(), I get a plot with bars as intended:

h <- ggplot(summary_data, aes(no_of_threads, max))
h + geom_bar()

However, when I create a line on this graph with geom_line(), ggplot generates an empty plot with no line in it:

h + geom_line()

How to plot my small dataset as a line graph using ggplot?

1
Interesting. I get an error with the first and the expected graphic with the second. On a Mac, in R64.app, R2.13.1, ggplot2_0.8.9. Maybe your object has a different structure? Why not instead post dput(summary_data)? - IRTFM
@DWin - the accepted answer is the right one. The summary data is calculated from the logs, and columns no_of_threads is actually a factor, not numeric variable. That gave me that behaviour. - Nikita Barsukov

1 Answers

5
votes

The only way I was able to reproduce your problem was if no_of_threads was a factor, rather than a numeric or integer variable. Try converting it to numeric:

summary_data$no_of_threads <- as.numeric(as.character(summary_data$no_of_threads))

Edit

I guess I'll add (assuming that I'm right about the cause of the problem) that switching back and forth isn't a hassle, really. Keep the variable as numeric, and when you want to use geom_bar, just do the coercion there:

ggplot(summary_data, aes(factor(no_of_threads), max)) + geom_bar()