How to increase the bars of a chart in R?

Asked

Viewed 164 times

1

Does anyone know what the command is to let the bars of the graph generated by the code below get wider?

library(lattice)

rend <- read.table("http://www.leg.ufpr.br/~walmes/cursoR/rendimento.txt",
               header=TRUE, sep="\t")
 rend <- transform(rend, K=factor(K), A=factor(A), bloc=factor(bloc))
(rend$Trat = with(rend, interaction(K, A)))
(médias.Trat = with(rend, tapply(rg, Trat, mean)))
barchart(rg~K|A, groups=médias.Trat, data=rend)
  • 3

    Rui, I think AP passed the data. They are being downloaded from the link http://www.leg.ufpr.br/~walmes/cursor/performance.txt . But I believe that the problem has no solution, not at least as the AP wishes. When I do length(médias.Trat), get 15. This implies that there are 15 groups being plotted. That is, although only 5 bars appear on each panel, there are 15 bars in total, which implies that the widths of the bars must be such that they fit 15 of them on each panel. In my view, it is impossible to solve this problem without decreasing the size of médias.Trat.

1 answer

1

I don’t quite understand the logic of groups=médias.Trat and unfortunately, I still don’t have a minimum score to comment on questions. I leave here my brief contribution and indication for use of the package ggplot2.

...
library(dplyr)
library(ggplot2)
rend_y <- data.frame(med_trat = médias.Trat) %>% 
  dplyr::add_rownames() %>%
  dplyr::rename("Trat" = rowname) %>% 
  dplyr::full_join(rend, by = "Trat") %>% 
  dplyr::mutate(Trat = as.factor(Trat))
rend_y %>% 
  ggplot2::ggplot() +
  geom_bar(aes(x = K, y = rg),
           stat = "identity", position = "dodge") +
  facet_grid(~A, scales = "free") +
  theme_light()

inserir a descrição da imagem aqui


I suggest updating the question and exposing some image so that we can better understand what Plot’s ultimate goal is and try to make the bars wider. In case of question update, I can update the answer. Maybe the solution path is in the object rend_y.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.