ggplot2 issue with y axis

I have the following means table:

   Sex Trait   Average
1    1    -N  9.042735
2    2    -N  3.529577
3    1     E  8.111111
4    2     E  9.447887
5    1     O 17.196580
6    2     O 16.311800
7    1     A 12.213680
8    2     A 13.449440
9    1     C 12.025640
10   2     C 14.529580

From where I run the following graph:

library(ggplot2)
plot <- ggplot(meansMatrix, aes(Trait, Average, colour= Sex,group= Sex)) +
      geom_line(aes(linetype=Sex),size=1) + 
      geom_point(size=3,fill="white") + 
      scale_color_manual(values = c("black", "grey50")) +
      scale_y_discrete(limits=c(0,18),breaks=seq(2,18,2.5),labels=seq(2,18,2.5)) +
      scale_x_discrete(limits=c("-N","E","O","A","C")); plot

There is visible a problem with the y axis. After setting the variable Average as numeric, I have tried with different combinations by changing the arguments (limits, breaks and labels) with no success. This is graph is the only that pops up else than error messages.

Any input of how to re-locate the plot and show the corresponding breaks will be highly appreciated!

Answers


Use scale_y_continuous:

meansMatrix <- read.table(text="   Sex Trait   Average
1    1    -N  9.042735
2    2    -N  3.529577
3    1     E  8.111111
4    2     E  9.447887
5    1     O 17.196580
6    2     O 16.311800
7    1     A 12.213680
8    2     A 13.449440
9    1     C 12.025640
10   2     C 14.529580", header=TRUE)

meansMatrix$Sex <- factor(meansMatrix$Sex)


library(ggplot2)
p <- ggplot(meansMatrix, aes(Trait, Average, colour= Sex,group= Sex)) +
  geom_line(aes(linetype=Sex),size=1) + 
  geom_point(size=3,fill="white") + 
  scale_color_manual(values = c("black", "grey50")) +
  scale_y_continuous(limits=c(0,18),breaks=seq(2,18,2.5),labels=seq(2,18,2.5)) +
  scale_x_discrete(limits=c("-N","E","O","A","C")) 

print(p)


Need Your Help

how to use select element onchange event to fill hidden element

html onchange hidden

Any help with this is greatly appreciated, as I've been pulling my hair out trying to make it work!

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.