Re: How to flip x-axis tick marks?

64 views
Skip to first unread message

Brandon Hurr

unread,
Oct 3, 2018, 5:17:06 PM10/3/18
to karl....@gmail.com, ggplot2

Negative length values, but it's all or nothing. Luckily, you've decided to get rid of your y-axis ticks so it should be fine. 

The theme settings in this gist seem right to me. 

HTH,
Brandon

On Wed, Oct 3, 2018 at 1:20 PM Karl Fetter <karl....@gmail.com> wrote:
Hello,

I made some plots a while back using the theme_economist() and my computer for some reason won't load or (re)-install ggthemes. So I'm out to remake the theme on my own. I'm nearly complete with what I want except for flipping the x-axis ticks up. Any idea how I can get the x-axis ticks pointing downward to point inward (into the plot?)

Here's my code so far:

Rplot01.jpegggplot(dat, aes(x=D_class,y=mantel_r)) +
        geom_point
(size = 3) + geom_line() +
        guides
(color=FALSE) +
        labs
(x="Pairwise geographic distance class (km)", y="Mantel r") +
       
#theme_bw() +
        scale_x_continuous
(labels=c("250", "500", "750", "1000"),
                           breaks
=c(250000, 500000, 750000, 1000000)) +
        theme
(axis.title.y = element_text(size=12),
              axis
.title.x = element_text(size=12),
              panel
.background = element_rect(fill="white"),
              plot
.background = element_rect(fill = "white"),
              panel
.grid.major = element_line(color="grey"),
              panel
.grid.major.x = element_blank(),
              panel
.grid.minor = element_blank(),
              panel
.border = element_blank(),
              axis
.line.x = element_line(size = 1),
              axis
.ticks.y = element_blank(),
              axis
.ticks.x.top = element_line())


Which produces this fig:


Rplot01.jpeg















But I want something with x-axis tick marks similar to this:

Untitled.jpg

Any help? 

Thanks!!

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marios Barlas

unread,
Oct 3, 2018, 6:31:45 PM10/3/18
to karl....@gmail.com, Brandon Hurr, ggplot2
Hi Brandon,

Just use theme (axis.ticks.length = unit(-1.6, "mm")) this will turn all your ticks in all axis inwards.

If you look in the theme handlers you can find also the corresponding option for isolated axes as well.

Best,
M.


From: ggp...@googlegroups.com <ggp...@googlegroups.com> on behalf of Brandon Hurr <brando...@gmail.com>
Sent: Wednesday, October 3, 2018 11:16:46 PM
To: karl....@gmail.com
Cc: ggplot2
Subject: Re: How to flip x-axis tick marks?
 

Brandon Hurr

unread,
Oct 3, 2018, 6:36:34 PM10/3/18
to marios...@gmail.com, karl....@gmail.com, ggplot2
"If you look in the theme handlers you can find also the corresponding option for isolated axes as well. "

Do tell. I didn't find this in my searches. There is no way to supply axis.ticks.length with anything but a single unit object as far as I can tell. 

For Karl, because he's getting rid of the y-axis ticks it's irrelevant, but if you want inside ticks on one axis and outside on the other... ¯\_(ツ)_/¯

Brandon

Brandon Hurr

unread,
Oct 3, 2018, 8:49:06 PM10/3/18
to marios...@gmail.com, ggplot2, karl....@gmail.com
Best not to take discussions off list so others can learn too. 

On Wed, Oct 3, 2018 at 5:42 PM Brandon Hurr <brando...@gmail.com> wrote:
Marios, 

I don't think I've been clear. 

If you want to set the x-axis ticks to be inside, but want to set the y-axis ticks to outside. This is what I think you can't do (but should be possible, I just don't know how). I also don't know if you can have a tick that goes across the axis (maybe a hjust/vjust thing?). 

library(ggplot2)

line.n.ticks <-1.0

ggplot(mtcars, aes(x = mpg, y = disp)) +
geom_point() +
    theme(panel.grid.major = element_blank(), 
          panel.grid.minor = element_blank(),
          line = element_line(colour = "black", size = line.n.ticks),
          panel.background = element_rect(linetype = 1, colour = "black", size = line.n.ticks),
          axis.line.x = element_line(colour = "black", size = line.n.ticks),
          axis.line.x.bottom = element_line(colour = "black", size = line.n.ticks),
          axis.line.x.top = element_line(colour = "black", size = line.n.ticks),
          axis.line.y = element_line(colour = "black", size = line.n.ticks),
          axis.line.y.left = element_line(colour = "black", size = line.n.ticks),
          axis.line.y.right =element_line(colour = "black", size = line.n.ticks),
          axis.ticks = element_line(colour = "black", size = line.n.ticks),
          axis.ticks.length = unit(-1.6, "mm"),
          axis.text.x = element_text(colour = "black", margin = margin(t = 8, r = 0, b = 7, l = 0)),
          axis.text.y = element_text(colour = "black", margin = margin(t = 0, r =8, b = 0, l = 7))
          )
Screen Shot 2018-10-03 at 5.41.45 PM.png
Ticks are inside for both x and y axes. 

Hopefully I'm more clear. This is more than what Karl was asking for and apologies to him for the curiosity. 

B

On Wed, Oct 3, 2018 at 3:47 PM Marios Barlas <marios...@gmail.com> wrote:
I actually didn't see who needed the handler lol.

@'Brandon Hurr' look at the description of the following handlers
axis.ticks.x, axis.ticks.x.top, axis.ticks.x.bottom, axis.ticks.y, axis.ticks.y.left, axis.ticks.y.right

And just use the element I provide in my function to customize accordingly. If u choose to set axis. ticks the rest inherit from that so don't overdefine things ;)

From: Marios Barlas <marios...@gmail.com>
Sent: Thursday, October 4, 2018 12:42:53 AM
To: Brandon Hurr

Subject: Re: How to flip x-axis tick marks?
 
Load this as a function and provide the required handlers. Then you can just call it in your ggplot plot by defining the required sizes et voilà you have a nice publishable theme. I also fix fonts with this so you'll need the package extrafont.

Read there :)

From: Brandon Hurr <brando...@gmail.com>
Sent: Thursday, October 4, 2018 12:36:09 AM
To: marios...@gmail.com
Cc: karl....@gmail.com; ggplot2
Reply all
Reply to author
Forward
0 new messages