Change x-axis interval

Hello, If someone can please help me to change x-axis intervals, I want a difference of 1 in between x-axis ticks. Also how i can use palette="pastel" for color?

Here is code:

H <- c(6.36, 3.03, 6.85, 4.07, 4.69, 6.27, 6.67, 3.11, 5.07, 6.14, 5.93, 6.49)
barplot(H,
        xlab = "Apperance liking on 9-point scale",
        ylab = "",
        xlim = c(0, 10),
        names.arg = c("Russian Banana", "Vermillion", "Atlantic", "POR12PG28-3", "Valery",
                      "Rio Colorado", "CO99076-6R", "Purple Majesty", "AC99330-1P/Y",
                      "CO05068-1RU", "Masquerade", "Canela Russet"),
        col = grey.colors(12),
        font.axis = 2,
        horiz = TRUE, las=1, font.lab=1, font.axis=1, border = NA)
abline(v=7, col = "magenta", lty = 5)

Created on 2020-07-13 by the reprex package (v0.3.0)

You could try the axis() function
put

?axis

in your console to read the documentation , which has examples also.

Aside from that, I would recommend to learn ggplot or plotly as charting solutions, they are very powerful and convenient, I would always use them myself before thinking about R's native plotting features... but that's personal taste maybe.

1 Like

Thanks @nirgrahamuk for the suggestion. Next time i shall go for ggplot.

Do you know if how i can change color and use color palette "pastel" and also how to improve aesthetic of character anchors, as they are overlapping x-axis ticks.
My code was:

#appearance
H <- c(6.36, 3.03, 6.85, 4.07, 4.69, 6.27, 6.67, 3.11, 5.07, 6.14, 5.93, 6.49)
barplot(H,
        xlab = "Apperance liking on 9-point scale",
        ylab = "",
        xlim = c(1, 9),
        names.arg = c("Russian Banana", "Vermillion", "Atlantic", "POR12PG28-3", "Valery",
                      "Rio Colorado", "CO99076-6R", "Purple Majesty", "AC99330-1P/Y",
                      "CO05068-1RU", "Masquerade", "Canela Russet"),
        col = grey.colors(12),
        font.axis = 2,
        horiz = TRUE, las=1, font.lab=1, font.axis=1, border = NA)
abline(v=7, col = "magenta", lty = 5)
axis(side = 1, at = 1:9, labels = c("Dislike\nExtremely", "", "3",
                                    "", "5", "", "7", "",
                                    "Like\nExtremely"))

Created on 2020-07-14 by the reprex package (v0.3.0)

you can change from grey.colors() and change the label size like this

        col = colorRampPalette(c("coral","pink"))(12),
        cex.names = .5,
1 Like

Thanks for the code. It worked on y axis but not on x-axis. Do you have any idea?

cex.axis for the tickmarks

1 Like

Thanks, I got the graph finally i want the way it should be. I tried to adjust the margins of the plot (like, top and bottom margins are too much) but they are not working, if you know how i can fix it.

Code -

#appearance
H <- c(6.36, 3.03, 6.85, 4.07, 4.69, 6.27, 6.67, 3.11, 5.07, 6.14, 5.93, 6.49)
tiff(file = "appearance.tiff", width = 2000, height = 2000, pointsize = 10, units = "px", res = 600)
barplot(H,
        xlab = "",
        ylab = "",
        xlim = c(0, 9),
        names.arg = c("Russian Banana", "Vermillion", "Atlantic", "POR12PG28-3", "Valery",
                      "Rio Colorado", "CO99076-6R", "Purple Majesty", "AC99330-1P/Y",
                      "CO05068-1RU", "Masquerade", "Canela Russet"),
        col = colorRampPalette(c("#6E5773","pink"))(12),
        font.axis = 2,
        cex.names = .6,
        cex.axis = .5,
        horiz = TRUE, las=1, font.lab=1, font.axis=1, border = NA)
abline(v=7, col = "magenta", lty = 5)
axis(side = 1, at = 1:9,
     labels = c("Dislike\nExtremely", "", "3", "", "5", "", "7", "", "Like\nExtremely"),
     cex.axis = .5)
par(mar = c(2, 0.5, 2, 2))
dev.off()
#> png 
#>   2

Created on 2020-07-14 by the reprex package (v0.3.0)

Does this help?

H <- c(6.36, 3.03, 6.85, 4.07, 4.69, 6.27, 6.67, 3.11, 5.07, 6.14, 5.93, 6.49)
par(mar = c(3, 9, 2, 2))
barplot(height = H,
        names.arg = c("Russian Banana", "Vermillion", "Atlantic", "POR12PG28-3", "Valery", "Rio Colorado", "CO99076-6R", "Purple Majesty", "AC99330-1P/Y", "CO05068-1RU", "Masquerade", "Canela Russet"),
        horiz = TRUE,
        col = colorRampPalette(colors = c("#6E5773","pink"))(n = length(x = H)),
        border = NA,
        xlab = "",
        ylab = "",
        xlim = c(0, 9),
        axes = FALSE,
        las = 1)
axis(side = 1,
     at = 1:9,
     labels = c("Dislike\nExtremely", "", "3", "", "5", "", "7", "", "Like\nExtremely"),
     font.axis = 1,
     cex.axis = 0.5)
abline(v = 7,
       col = "magenta",
       lty = 5)

Created on 2020-07-14 by the reprex package (v0.3.0)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.