1

Here is my code

ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() + theme_clean() 

I want to remove the y-axis black line. This is my desired results enter image description here

Best,

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
RL_Pug
  • 697
  • 7
  • 30
  • 1
    Does this answer your question? [can I separately control the x and y axes using ggplot?](https://stackoverflow.com/questions/6541329/can-i-separately-control-the-x-and-y-axes-using-ggplot) – UseR10085 Apr 14 '20 at 14:56
  • Which black line are you talking about? – Jack Brookes Apr 14 '20 at 15:02

2 Answers2

2

Try this (using theme_classic, which is kind of close to your desired result, but has both x and y axis lines present):

ggplot(mtcars, aes(mpg, hp)) + 
    geom_point() + theme_classic() +
    theme(axis.line.y = element_blank(), axis.line.x = element_line())

enter image description here

If you type theme_classic (no parenthesese), you can see all the theme elements that are used to create that theme. Note that the classic theme has axis.line applied, which creates both x and y axis lines. If you try only specifying axix.line.y = element_blank(), it does not work, since theme_classic() applies axis.line back over that command - resulting in both lines again. This is why you have to specify both here.

chemdork123
  • 12,369
  • 2
  • 16
  • 32
0

Use the folowing code

library(ggthemes)

ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() + theme_hc() + 
  theme(axis.line.y = element_blank(), axis.line.x = element_line())

enter image description here

If you want to have an answer according to your code then

ggplot(mtcars, aes(mpg, hp)) +
  geom_point() +
  theme_clean()+
  theme(axis.line.y = element_blank(), axis.line.x = element_line(), plot.background=element_blank())

enter image description here

UseR10085
  • 7,120
  • 3
  • 24
  • 54