0

I am using ggplot to draw the "score vs memberID" distribution of the following dataframe. "memberID"s are ordered in the descending order of "Score"

In my real dataset I have 1000 member IDs and when I use the same code, x - axis labels are not visible. I just want to get a few of the labels visible (e.g., every 50th). Since I order the member IDs in descending order of scores I am not sure how to get only a few x-axis labels.

Could someone help me in this matter pls.

test <- read.table(text=" memberID SCORETYPE     Score
 0   score.1 0.7123645
 1   score.1 0.4893589
 2   score.1 0.6294229
 3   score.1 0.6051377
 4   score.1 0.1411411
 5   score.1 0.5173978
 6   score.1 0.5355791
 7   score.1 0.5946272
 8   score.1 0.1328829
 9   score.1 0.2012012
 10   score.2 0.6624559
 1   score.2 0.5306829
 2  score.2 0.5723985
 3   score.2 0.1839339
 4   score.2 0.5883927
 5   score.2 0.6020042
 6   score.2 0.6098381
 7   score.2 0.4739522
 8   score.2 0.4430409
 9   score.2 0.5831375
 10  score.2 0.2531375
  " ,header = TRUE)

plottest <- ggplot(data=test,aes(x=reorder(memberID,-Score),Score,group=SCORETYPE,colour=SCORETYPE))+geom_point()+geom_line()+xlab("User")
plottest <- plottest+theme(text = element_text(size=10),axis.text.x = element_text(angle = 90, hjust=0,size=10),legend.text=element_text(size=10))
plottest <- plottest + theme(axis.line.x = element_line(color="black", size = 1),axis.line.y = element_line(color="black", size = 1))
plottest

This image is what I get from the example enter image description here

This image is what I get for my real data. I only want to display a few axis labels in here enter image description here

Anna
  • 83
  • 9
  • The tricky part about setting scale_x_discrete is your member ID is not in numerical order, is there a reason for this? – Djork Mar 10 '17 at 02:27
  • I wanted to get the graph with the descending order of scores (as in second figure) . Then memberID s not in the numerical order. – Anna Mar 10 '17 at 02:36
  • 1
    I see that now, but displaying only a few x labels makes no sense as they are not in numerical order. There will be no logic to the intervals of x-axis labels. You might as well just turn off all the labels by setting `theme(axis.text.x=element_blank())` – Djork Mar 10 '17 at 02:44
  • thanks for the suggestion – Anna Mar 10 '17 at 02:50

0 Answers0