r - How do you label a horizontal line when the x axis is categorical? -


One shows how to label a straight line in R by using ggplot2. Please see Example 5 - "Rebuild the following conspiracy of the amount of flight by the longitude".

If X-axis is clarified instead of continuous, how do you code?

  data = data.frame (x = - 119, y = 0)   

How to I have created a line

  + geom_text (AES (X, Y, label = "serial"), data = data.frame (x = 1, y = 20), size = 4, And I tried several options  
  data = data.frame (x = 1, Y = 20) data = data.frame (x = factor (1), y = 20) #where gard is the name of a data in categories = data.frame (x = "gard", y = 20)   

... but I get an error

Invalid argument for inappropriate operator

It is not completely clear what you are trying to do, because you say that you try to make a line, and then your code geom_text Using a specific x variable, assuming that you want to keep a vertical line, with a text label on the vertical line on that line, here is a simple example:

 < Code> dat & lt; - data.frame (X = letters [1: 5], y = 1: 5) txt & lt; Ggplot (dat, aes (x = x, y = y)) + geom_point () + geom_vline (xintercept = 1.5) + geom_text (data = frames (x = 1.5, y = 1, lab = "label" Txt, AES (label = lab), angle = 90, hjust = 0, vjust = 0)   

This output on my machine produces:

Enter image details here

Note that I have a text label in a different data frame, Em> out ggplot in the call. It is not strictly necessary, but I like it because I think it avoids the illusion.

Using the X value of 1.5 for the text label works here, as you'd like, you want to set "a" on the directly-drawn X values.

The error you are describing for me has suggested a simple syntax error (which you have not provided completely) anywhere in your code. Perhaps this example will help you find it.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -