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

  • Home
  • SEARCH
  • 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 8092937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:23:40+00:00 2026-06-05T20:23:40+00:00

I have a dataframe called split2_data (actually a drop-leveled subset of a bigger data

  • 0

I have a dataframe called split2_data (actually a drop-leveled subset of a bigger data frame).
It contains a column “Loci”, which are factors that I want as x-axes, and several columns of y-values (note: All of these values are <=1) that I would like to plot beside one another in their respective x factor.

The dataframe

structure(list(Loci = structure(1:8, .Label = c("C485", "C487_PigTa", 
"C536", "Carey", "Cool", "Coyote", "Deadpool", "Epstein"), class = "factor"), 
All = structure(c(5L, 6L, 7L, 1L, 2L, 4L, 3L, 8L), .Label = c("0.0246", 
"0.0352", "0.0563", "0.0646", "0.2349", "0.3242", "0.3278", 
"0.6854"), class = "factor"), X1_only = structure(c(4L, 3L, 
2L, 1L, 6L, 6L, 6L, 5L), .Label = c("0.0133", "0.7292", "0.8586", 
"0.9377", "0.961", "1"), class = "factor"), X78_only = structure(c(7L, 
6L, 4L, 5L, 8L, 3L, 1L, 2L), .Label = c("0.0018", "0.0175", 
"0.4958", "0.6055", "0.7472", "0.7563", "0.825", "1"), class = "factor"), 
X8_removed = structure(c(5L, 6L, 8L, 1L, 2L, 3L, 4L, 7L), .Label = c("0.0181", 
"0.0348", "0.1482", "0.1706", "0.2217", "0.2602", "0.6748", 
"0.7123"), class = "factor"), X8_only = structure(c(6L, 7L, 
3L, 8L, 5L, 4L, 1L, 2L), .Label = c("0.1266", "0.1945", "0.4389", 
"0.4496", "0.7078", "0.709", "0.8882", "1"), class = "factor"), 
X7_removed = structure(c(6L, 4L, 5L, 2L, 1L, 3L, 7L, 8L), .Label = c("0.0159", 
"0.02", "0.0541", "0.3232", "0.3972", "0.4226", "0.4919", 
"0.5951"), class = "factor"), X7_only = structure(c(3L, 4L, 
7L, 5L, 6L, 8L, 1L, 2L), .Label = c("0.0082", "0.1759", "0.4957", 
"0.5248", "0.6665", "0.6789", "0.8372", "1"), class = "factor"), 
X5_removed = structure(c(5L, 7L, 6L, 1L, 3L, 4L, 2L, 8L), .Label = c("0.0195", 
"0.0316", "0.08", "0.1069", "0.1549", "0.395", "0.4405", 
"0.6298"), class = "factor"), X5_only = structure(c(1L, 2L, 
6L, 7L, 3L, 5L, 7L, 4L), .Label = c("0.0871", "0.2022", "0.3532", 
"0.3677", "0.5292", "0.7602", "1"), class = "factor"), X4_removed = structure(c(8L, 
4L, 7L, 2L, 3L, 5L, 1L, 6L), .Label = c("0.0188", "0.0194", 
"0.0511", "0.1716", "0.1862", "0.6454", "0.661", "0.8003"
), class = "factor"), X4_only = structure(c(2L, 5L, 1L, 6L, 
7L, 3L, 8L, 4L), .Label = c("0.0026", "0.0378", "0.2884", 
"0.4386", "0.5116", "0.6549", "0.6928", "1"), class = "factor"), 
X3_removed = structure(c(5L, 7L, 6L, 1L, 2L, 3L, 4L, 8L), .Label = c("0.0612", 
"0.0627", "0.0808", "0.1636", "0.2728", "0.477", "0.5307", 
"0.6506"), class = "factor"), X3_only = structure(c(8L, 1L, 
7L, 2L, 4L, 6L, 3L, 5L), .Label = c("0.0225", "0.2111", "0.2471", 
"0.5087", "0.6294", "0.768", "0.8263", "0.8951"), class = "factor"), 
X2_removed = structure(c(4L, 5L, 6L, 3L, 7L, 2L, 1L, 8L), .Label = c("0.0526", 
"0.0608", "0.0854", "0.2036", "0.3168", "0.3668", "0.413", 
"0.7608"), class = "factor"), X2_only = structure(c(5L, 3L, 
6L, 4L, 2L, 8L, 1L, 7L), .Label = c("-", "0.0014", "0.0949", 
"0.1637", "0.1818", "0.5521", "0.8585", "1"), class = "factor"), 
X1_removed = structure(c(5L, 7L, 3L, 6L, 1L, 4L, 2L, 8L), .Label = c("0.0258", 
"0.031", "0.0496", "0.0676", "0.1053", "0.1439", "0.2823", 
"0.5465"), class = "factor")), .Names = c("Loci", "All", 
"X1_only", "X78_only", "X8_removed", "X8_only", "X7_removed", 
"X7_only", "X5_removed", "X5_only", "X4_removed", "X4_only", 
"X3_removed", "X3_only", "X2_removed", "X2_only", "X1_removed"
), row.names = 9:16, class = "data.frame")

I can’t think of how to do this in base R, and after some careful study of other questions here, this is the best that I can come up with:
library(reshape)
library(ggplot2)
require(ggplot2)

split2_datam<-melt(split2_data,id="Loci")


p2<- ggplot(split2_datam, aes(x =Loci, y = value, color = variable, width=.15)) + geom_bar(position="dodge") + ylab("P-value")+ geom_hline(yintercept=0.05)+ opts(axis.text.x  = theme_text(angle=90, size=8)) + scale_y_discrete(breaks=seq(0,1)) + scale_fill_grey()
p2


#when I add stat="identity", the y values don't change- they just shrink relative to the x-axis
p2<- ggplot(split2_datam, aes(x =Loci, y = value, color = variable, width=.15)) + geom_bar(position="dodge", stat="identity") + ylab("P-value")+ geom_hline(yintercept=0.05)+ opts(axis.text.x  = theme_text(angle=90, size=8)) + scale_y_discrete(breaks=seq(0,1)) + scale_fill_grey()
p2

The plot:
enter image description here

You’ll notice that the different variables are often much greater than 1. They should not be. Any idea what’s causing this/how to fix?

Other things I don’t yet know how to do/fix (perhaps this question should be cross-referenced?):

  1. I don’t know why the greyscale isn’t working
  2. I don’t know how to make the legend scale correctly with the plot
  3. I don’t understand why my columns have an ‘X’ appended to them (e.g. “X1_only” instead of “1_only”)

Thank you so much in advance for any suggestions!

  • 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-05T20:23:41+00:00Added an answer on June 5, 2026 at 8:23 pm

    Your data have been read in as factors, probably because there are some “-” characters mixed in with your data.

    You’ll want to convert them to NA when you read in your data using na.strings = "-".

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

Sidebar

Related Questions

I have a data.frame called series_to_plot.df which I created by combining a number of
I have a data.frame , called so_data. Columns 13:23 are list s, which hold
I have a file, called genes.txt , which I'd like to become a data.frame.
I have a data frame called data which I read in from a CSV
I have got a data frame (which is called data.set.y). And I would like
I have a dataframe called prices_df to which I add an extra column and
I have a data frame with multiple columns, one of which (called: drift.N) is
I'm new to R. I have a a Data.frame with a column called Symbol.
I have a data.frame in R; it's called p . Each element in the
I have a dataframe with distances df<-data.frame(site.x=c(A,A,A,B,B,C), site.y=c(B,C,D,C,D,D),Distance=c(67,57,64,60,67,60)) I need to convert this to

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.