How to show all values on x axis

15,684 views
Skip to first unread message

Nicippe B

unread,
Oct 9, 2013, 6:56:20 AM10/9/13
to ggp...@googlegroups.com

Hi All,
I have created a plot using ggplot which only shows 3 values from a total of 12. How can I force ggplot to show all values of x-axis? Sample data and code found below

 

 structure(list(df = c(3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L), .Label = c("est", "lcl", "ucl"), class = "factor"),
value = c(0.00531397286604541, 0.00465302613078271, 0.00599206328501424,
0.0063936544582357, 0.00583732007007508, 0.00570938070638182,
0.00508940797065789, 0.00499908774197153, 0.00535179179636405,
0.00504072124147188, 0.00179543852941809, 0.00100094651094594,
0.00227307755709763, 0.0026302975491651, 0.00204051039581486,
0.00188950350263121, 0.00125031219694319, 0.00113596705257451,
0.00145629986966463, 0.00112650714659818, 0.00883250720267273,
0.00830510575061949, 0.00971104901293084, 0.0101570113673063,
0.00963412974433531, 0.00952925791013243, 0.00892850374437259,
0.00886220843136856, 0.00924728372306347, 0.00895493533634557
)), .Names = c("df", "variable", "value"), row.names = c(NA,
-30L), class = "data.frame") 

 

ggplot(data=df, aes(x=df, y=value, group=variable)) + geom_line(aes(color=variable))

 


Many thanks

Brandon Hurr

unread,
Oct 9, 2013, 7:26:32 AM10/9/13
to Nicippe B, ggplot2
ggplot(data=df, aes(x=factor(df), y=value, group=variable)) + geom_line(aes(color=variable))

?


--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
 
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

David Guy

unread,
Oct 9, 2013, 8:17:01 AM10/9/13
to Brandon Hurr, Nicippe B, ggplot2
Nicippe,

Brandon's suggestion is a slam dunk. However,for future references if you want to control the x(or y axis) you might like to use:

pp<-ggplot(data=df, aes(x=df, y=value, group=variable)) + geom_line(aes(color=variable))
pp+scale_x_continuous(breaks=c(3:12), labels=c(3:12),limits=c(3,12))


HTH

David

--
David Guy, PhD
R Statistical Consulting Inc.
Flemington, NJ USA
 
Office: 908-237-5107
Cell:    917-941-5890
Fax:    908-284-0356
Skype: david.guy1213


Nicippe B

unread,
Oct 11, 2013, 3:09:43 PM10/11/13
to David Guy, Brandon Hurr, ggplot2
Thank you both for working code.
Reply all
Reply to author
Forward
0 new messages