Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6071637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:04:13+00:00 2026-05-23T10:04:13+00:00

I am developing a graph in R with ggplot2 that has two geoms (one

  • 0

I am developing a graph in R with ggplot2 that has two geoms (one geom_line and one geom_text). It draws a line graph and then places text labels on start and end points of each line segment.

  (myplot <- ggplot(data=datatable, aes(x, y, group = group,colour = group, label=mylabels)) + geom_line(size = 1.5))  
  myplot + geom_text(color = "black") 

Now my question is how can I do the following tasks in ggplot2, they all work when I only have one geom but not with both (seems that they overide each other)

1 – making the background white.
The following code works with geom_line but as soon as I add geom_text it becomes gray again. Even if I add this line after geom_text it gets rid of the point labels that are on the chart.

myplot + opts(panel.background = theme_rect(fill = "white", colour = NA)) 

2- x labels and x label format. Again the following code works with only one geom but breaks when I have the second geom

myplot + scale_x_date(format="%m", 'my x label')

3- While we are on it how can I put the legend at the bottom and spread it horizontally (p + opts(legend.position=”bottom”)) spreads that vertically that looks very stupid.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:04:13+00:00Added an answer on May 23, 2026 at 10:04 am

    For 1), you haven’t saved the object myplot after the second and third calls involving it. This works for me:

    set.seed(3)
    dat <- data.frame(x = runif(10), y = rnorm(10), group = gl(2,5),
                      mylabel = paste(1:10, "foo"))
    
    require(ggplot2)
    myplot <- ggplot(data=dat, aes(x, y, group = group, colour = group, 
                     label = mylabel)) + geom_line(size = 1.5)
    
    myplot + geom_text(color = "black") + 
        opts(panel.background = theme_rect(fill = "white", colour = NA))
    

    Note that I only ever save myplot once. The second call involving myplot modifies it on the fly but doesn’t save it.

    For the rest, you’ll need to provide a reproducible example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Java Swing GUI that I'm developing needs to plot a 2D graph based
I am developing a web application that manages a population of plants. One feature
I am developing native iPhone app. I have one requirement that, there are 5
When developing an application that sends out notification email messages, what are the best
I'm developing a graph control in WPF. I have previously developed it using GDI
I'm developing a graph control in WPF. I need to place a Canvas on
I am developing a Graph-class, based on boost-graph-library. A Graph-object contains a boost-graph, so
I've just started developing a small C++ program using GraphViz's graph library and noticed
I started developing a Facebook app using the new Graph API. I want to
I'm developing a graphing application that on the main navigation/tab view displays a UIView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.