user111024
user111024

Reputation: 811

Remove primary x axis and keep only duplicated secondary axis in ggplot

This is silly. But how I can remove the x axis on the bottom of a ggplot and keep only the secondary axis?

foo <- tibble(x=1:100,y=rnorm(100))
ggplot(foo,aes(x=x,y=y)) + geom_line() +
  scale_x_continuous(sec.axis = dup_axis())

EDIT: Thanks to the comments...solved.

ggplot(foo,aes(x=x,y=y)) + geom_line() +
  scale_x_continuous(position ="top")

Upvotes: 1

Views: 1359

Answers (2)

user111024
user111024

Reputation: 811

Embarrassing. I didn't know about the position="top" option. Thanks.

foo <- tibble(x=1:100,y=rnorm(100))
ggplot(foo,aes(x=x,y=y)) + geom_line() +
  scale_x_continuous(position ="top")

Upvotes: 1

廖健龙
廖健龙

Reputation: 58

You could set axis.x.bottom parameters in theme. Try:

foo <- tibble(x=1:100,y=rnorm(100))
ggplot(foo,aes(x=x,y=y)) + geom_line() +
  scale_x_continuous(sec.axis = dup_axis()) +
  theme(axis.text.x.bottom = element_blank(), axis.ticks.x.bottom = element_blank(), axis.title.x.bottom = element_blank())

Upvotes: 1

Related Questions