Changing the order of values on the x-axis in R -


i attempting create line graph (time vs anxiety) in r x-axis ranging 10am 6pm. r, however, reorders values in numeric order , graph looks vaguely 's-shaped'. please see below vectors:

anxiety <- c(1, 1, 2, 2, 3.5, 4, 4.5, 5, 5) time <- c(10, 11, 12, 1, 2, 3, 4, 5, 6)  plot(time, anxiety, xlab='time (hour of day)', ylab='degree of anxiety (estimated)', xaxt='n', main='the effect of technology deprivation on anxiety', col='blue', type='l', cex.lab=1.5, cex.main=1.5, las=1) 

i prefer x-axis values presented in chronological order (10am, 11am, etc.) , graph reflect near linear pattern of increasing anxiety.

thanks all.

~caitlin

if willing give ggplot2 try

# data anxiety <- c(1, 1, 2, 2, 3.5, 4, 4.5, 5, 5) time <- c(10, 11, 12, 1, 2, 3, 4, 5, 6) df <- data.frame(anxiety, time) # order level of time df$time <- factor(df$time, order=true, levels=time)  # plot ggplot(df, aes(x=time, y=anxiety, group=1)) + geom_line() 

enter image description here


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -