r - Only show last four labels on bar graph -


my code here produces bar graph labels on each bar of y value.
show last 4 data points labels. best way it? enter image description here

library(data.table) library(ggplot2)  df <- data.table(x= c(1,2,3,4,5,6,7,8,9,10), y=c(4,1,-3,-5,4,1,2,4,2,-3))  ggplot(df, aes(x=x, y=y)) +         geom_bar(stat="identity") +         geom_text(aes(y=y, ymax=y, label=y),                    position= position_dodge(width=0.9), vjust=-.5, color="red") 

thank much.

thanks @user20650 quick response. subsetting gem_text did trick. thank much!

here updated code:

library(data.table) library(ggplot2)  df <- data.table(x= c(1, 2, 3, 4, 5,6,7,8,9,10), y=c(4, 1,-3,-5,4,1,2,4,2,-3))  ggplot(df, aes(x=x, y=y)) +         geom_bar(stat="identity") +         geom_text(data=subset(df, x>6), aes(y=y, ymax=y, label=y),                    position= position_dodge(width=0.9), vjust=-.5, color="red") 

enter image description here


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -