user3415921
user3415921

Reputation: 31

how to manually set values for X axis

I read data from two files "80211" and "newfile". both of them have one column data without any header. I have the below code but I can't set the x axis values manually. In the figure, the x values appear as 1 and 2 but I need to do it manually. (they are 1 and two because there is no header and they will give 1 and 2 automatically)

data1 <- scan(pipe('cut -f1 -d, 80211'))
data2 <- scan(pipe('cut -f1 -d, newfile'))

df <- data.frame(x = c(data1, data2), ggg=factor(rep(1:2, c(19365,19365))))

ggplot(df, aes(x=ggg, y=x, fill=ggg)) + 
geom_jitter(alpha=0.5, aes(color=ggg),position = position_jitter(width = .2)) + 
guides(fill=FALSE) + scale_y_continuous(breaks=seq(0, 200, 10)) +
xlab('') +
ylab('IRT (ms)')

This the results but I want to name the x axis values with "ieee" and "mine" instead of 1 and 2.

enter image description here

Upvotes: 0

Views: 4847

Answers (1)

bjoseph
bjoseph

Reputation: 2166

You can control x axis labelling in ggplot using scales and labels. See the documenation here: http://docs.ggplot2.org/current/scale_continuous.html or http://docs.ggplot2.org/current/scale_discrete.html. In your case I believe the below will work, although i was unable to replicate your dataset.

ggplot(df, aes(x=ggg, y=x, fill=ggg)) + 
geom_jitter(alpha=0.5, aes(color=ggg),position = position_jitter(width = .2)) + 
guides(fill=FALSE) + scale_y_continuous(breaks=seq(0, 200, 10)) +
xlab('') +
ylab('IRT (ms)') +
scale_x_discrete(breaks = c(1,2),labels=as.character(c("ieee","mine")))

Upvotes: 1

Related Questions