Reputation: 69
I'm struggling with a plot. I have a vector "a":
h1 h2 h3 h4
1.000 0.880 0.746 0.761
These are data of normalized concentration of an element in a soil profile.
I would like to have on the x
axis the concentration (1, 0.880, 0.746, 0.761)
and on the y
axis the different horizons (h1, h2, h3, h4)
. But I would like the y
axis to go downward (as in a soil profile), and the x
axis on the top of that plot.
Here's what I've got so far: (I have tried many other things but without success)
test=factor(names(a))
plot(a,test)
axis(3)
This shouldn't be so hard but even after checking ?axis
, ?plot
and ?par
, I can't manage to get what I want.
Upvotes: 0
Views: 262
Reputation: 3994
Instead of that, you may want to customize your plot:
require(ggplot2)
a <- data.frame(horizon = c("h1", "h2", "h3", "h4"), vals = c(1.000, 0.880, 0.746, 0.761))
ggplot(a, aes(x = vals, y = horizon)) +
geom_point() +
scale_y_discrete(limits = rev(levels(a$horizon)))+
scale_x_continuous(position = "top")
The ggplot2
package is far easier to customize.
Upvotes: 1