Change x scale to range from 0 to 100 but showing decimal variations

Asked

Viewed 54 times

1

Hello, I need to plot the decimal variations on the x-axis and vary from 0 to 100

fevmt=c(91.9, 92.1, 92.3, 91.4, 91.8, 90.1, 91.8)

a1 =c(91.9, 100)
b1 =c(92.1, 100)
c1 = c(92.3, 100)
d1 =c (91.4, 100)
e1 = c (91.8, 100)
f1 = c(90.1, 100)
g1 =c (91.8, 100)



mt_2  <- cbind(a1, b1, c1, d1, e1, f1 ,g1 )
mt2 <- as.matrix(mt_2)
rownames (mt2)<- c("Model", "Pereira et al")
colnames(mt2) =c("18 to 23", "24 to 29", "30 to 35", "36 to 41", "42 to 47", "48 to 53", 
                 "54 to 59")


barplot(mt2, font.axis=2, beside = T, ylim = c(min(fevmt)-2, max(re)),
        axes = F,  xlab = "Ages", font.lab = 2,  sub = "Males", xpd = F, 
        ylab = "% FEV1", width = 50,  col = c("cornsilk3", "cornsilk4"))
legend("bottomright", legend=c("Pereira et al.", "Model"),  fill = c("cornsilk3", "cornsilk4"), 
       box.lty = 0, horiz = T, inset = c(0,1), xpd = T , bty = "n")
axis(2, at = seq(floor(min(fevmt)-2), ceiling(max(re)), by = .5))
box()
  • 1

    From 0 to 100 with decimal variations are thousand dashes?

  • Besides what I said above, it gives "barplot.default error: object’re' not found".

  • 1

    Moreover, as.matrix(mt_2) does nothing, mt_2 is already a class object "matrix". (But it doesn’t hurt either, it’s just unnecessary.)

1 answer

2

You’ll be looking for a chart like this?

library(tidyverse)
library(scales)

y_limites <- range(mt2) - c(2, 0)

as.data.frame(mt2) %>%
  mutate(Autor = row.names(.)) %>%
  gather(Intervalo, Valor, -Autor) %>%
  ggplot(aes(x = Intervalo, y = Valor, fill = Autor)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_y_continuous(limits = y_limites, oob = rescale_none) +
  scale_fill_manual(values = c("cornsilk3", "cornsilk4")) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

inserir a descrição da imagem aqui

Browser other questions tagged

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