How to make the data display on the x-axis look clearer

Dear all,

I would like to ask a help for my problem. I have some data around 1699 columns and 192 rows.
When I tried to make a graph with geom_hline in gggplot packages, the data in X-axis were difficult to distinguish and not easy to be seen. Here, how my data looks like

and here my scripts,

data.col = c("Name", "Pvalue", "estimate", "Pvalue_LOG") # Column names
Table = matrix(NA, nrow=length(csv)-2, ncol=length(data.col)) # Create empty dataframe
colnames(Table) = data.col # Set column names

##################

data insertion

################
for (i in 3:1699) {
result = cor.test(csv$length, csv[,i])
Name = colnames(csv)[i]
Pvalue = result$p.value
estimate = result$estimate
Pvalue_LOG = -log10(Pvalue)
tmp = c(Name, Pvalue, estimate, Pvalue_LOG)
Table[i-2, ] = tmp # Add curent analysis to empty NxM dataframe
}

#summary(data)
write.csv(Table, "trial_CI.csv", row.names=FALSE) # Output as csv file
##############

Plot graph

##############
library(ggplot2)
csv = read.csv("trial_CI.csv", na.strings="NA")
#csv.2 = subset(csv, csv$Pvalue < 0.05) # Create dataset without p>=0.05
#csv.3 = subset(csv.2, csv.2$estimate > 0) # Create dataset without estimate<0

ggplot settings

mytheme = theme_bw() + theme(axis.text.x = element_text(size=8, face="bold", hjust=1, angle=45),
axis.title.x = element_text(size=24, face="bold"),
axis.text.y = element_text(size=16, face="bold"),
axis.title.y = element_text(size=24, face="bold")
)

ggplot settings

theme_set(mytheme)

plot

A = ggplot(csv, aes(Name, estimate)) +
geom_jitter(size=3, alpha=1, width=0.1) +
geom_hline(yintercept=0) +
scale_y_continuous(breaks=seq(-1, 1, by = 0.1), limits = c(-1, 1))+
ylab("r")
print(A)
B = ggplot(csv, aes(Name, Pvalue_LOG)) +
geom_jitter(size=3, alpha=1, width=0.1) +
geom_hline(yintercept=1.4,linetype="dashed") +
scale_y_continuous(breaks=seq(0,100,1))+
theme(axis.text.y = element_text(size=8))+
ylab("-log10(P)")
print(B)
pdf("trial_CIresultA.pdf", width = 15, height = 10)
print(A)
dev.off()
pdf("trial_CIresultB.pdf", width = 15, height = 10)
print(B)
dev.off()

Output as pdf file

library("gridExtra")
pdf("trial_CIresultAB.pdf", width = 15, height = 10)
layout1 = rbind(c(1, 2))
grid.arrange(A, B, nrow = 2, layout_matrix = layout1)
dev.off()

How can I change my scripts to make the data display on x-axis look clearer and easy to distinguish?
I appreciate for your help.
Thank you so much.

I think there is too much X argument and it would be difficult to clean x axis. But I have some offers:

  1. delete observations with missing Y values;
  2. choose lower size for axis.text.x
  3. rotate coordinates with coord_flip function. see here

I tried to use coord_fip function but the graph looks like more messy @Lev_ani

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.