The Conservative leader in the Welsh Parliament, Andrew RT Davies, has resigned after narrowly surviving a vote of confidence of his party colleagues.