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 8987321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:45:43+00:00 2026-06-15T21:45:43+00:00

I am trying to organize the labels of my ggplot scatterplot so that the

  • 0

I am trying to organize the labels of my ggplot scatterplot so that the labels don’t overlap with one another. For this purpose, I am trying to use the direct labels library but I cannot get it to work. When I tried the code:

mytable <- read.csv('http://www.fileden.com/files/2012/12/10/3375236/My%20Documents/CF1_deNovoAssembly.csv', sep=",",  header=TRUE)

mytable$Consensus.length <- log(mytable$Consensus.length)

mytable$Average.coverage <-log(mytable$Average.coverage)

mytable$Name <- do.call(rbind,strsplit(as.character(mytable$Name), " ", '['))[,3]

ggplot(mytable, aes(x=Consensus.length, y=Average.coverage, label=Name)) + geom_point() + ylab("Contig Average Coverage (log)") + xlab("Contig Consensus Length (log)") + opts(title="Contig Coverage vs Length") + geom_text(hjust=0, vjust=-0.2, size=4)
direct.label(p, "first.qp")

I got this error:

Error in direct.label.ggplot(p, "first.qp") : 
  Need colour aesthetic to infer default direct labels.

So I changed the plotting script by adding aes to the geom_point()

ggplot(mytable, aes(x=Consensus.length, y=Average.coverage, label=Name)) + geom_point(aes(colour=Average.coverage)) + ylab("Contig Average Coverage (log)") + xlab("Contig Consensus Length (log)") + opts(title="Contig Coverage vs Length") + geom_text(hjust=0, vjust=-0.2, size=4)

And now I get the following error

Error in order.labels(d) : labels are not aligned

I found this thread in which they suggest either placing the labels manually if only a few data points or not at all if too many data points. I agree with this but I will be generating this graph with many different data sets and I do need the data labels. So far this is how the graph looks
enter image description here

  • 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-06-15T21:45:44+00:00Added an answer on June 15, 2026 at 9:45 pm

    From your comments, it sounds a bit more like a clustering exercise. So, let’s go ahead and actually do so:

    set.seed(9234970)
    d <- data.frame(Name=mytable$Name, 
    x=mytable$Consensus.length, 
    y=mytable$Average.coverage)
    d$kmeans <- as.factor(kmeans(d[-1],20)$cluster)
    ggplot(d, aes(x, y, color=kmeans)) + 
    geom_point() + 
    theme(legend.position="bottom")
    

    kmeans clusters
    ggplot(d, aes(x, x, label=Name)) +
    geom_text(aes(x,y)) +
    facet_wrap(~kmeans, scales=”free”)

    Cluster Breakout

    I chose 20 clusters at random

    You could also use heirarchical clustering to see a dendogram.

    plot(hclust(dist(d[-3]))) # -3 drops kmeans column

    I’d recommend playing around with the cluster package in general as it may provide a more useful solution to your problem.

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

Sidebar

Related Questions

I am trying to organize 3 LinearLayouts, such that one is justified to the
I am trying to organize a Zip Archive into an array so that I
I have Python nested list that I'm trying to organize and eventually count number
As documented here: http://www.jblotus.com/2011/05/24/keeping-your-handlebars-js-templates-organized/ I am trying to use this function: ( function getTemplateAjax(path,
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I am trying to organize my program into functions and have ran into this,
I'm trying to organize my Rails application into two namespaces that provide the same
I am trying to use django to organize and manage my clinical research data.
Im trying to organize this kind of array array 0 => array 'id' =>
I'm trying to organize my code flexible. So my application makes heavy use of

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.