r - Horizontal barplot labels overlapping on each other -


i using dataset create horizontal in horizontal orientation. similar has been proposed solution in r: how can make barplot labels parallel (horizontal) bars.

however, number of labels in y axis of horizontal barplot chart little many (due problem in hand) , hence, overlapping on each other.

is there way preserve barplot bin size , show subset of y labels in horizontal orientation of barplot?

thanks, rajat

here's 1 way it, can use nice solution interleave names data blanks:

generate data

set.seed(123) df1 <- data.frame(x = replicate(50, paste(sample(letters, 2, replace = t), collapse = '')),                   y = sample(1:10, 50, replace = t), stringsasfactors = false) 

make barplot, using subset of names

barplot(df1$y, names.arg = c(rbind(df1$x, rep('', 50)))[1:50], horiz = t, las = 1) 

the main trick names.arg = c(rbind(df1$x, rep('',50)))[1:50] line. interleaves blanks between names data. effectively, replacing half of names blank space.

if that's not sufficient, can define function takes in vector of names, x, , multiple, m defines values replace blanks:

replace_multiple <- function(x, m){     len_x <- length(x)     index_to_replace <- seq(1, len_x, = m)     x[index_to_replace] <- ''     return(x) }  replace_multiple(letters[1:12], m = 2) # ""  "b" ""  "d" ""  "f" ""  "h" ""  "j" ""  "l" replace_multiple(letters[1:12], m = 3) # ""  "b" "c" ""  "e" "f" ""  "h" "i" ""  "k" "l" replace_multiple(letters[1:12], m = 4) # ""  "b" "c" "d" ""  "f" "g" "h" ""  "j" "k" "l" 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -